Skip to content

Instantly share code, notes, and snippets.

@jeepitou
Forked from selfire1/marvin-toggl-tracking.sh
Last active June 17, 2021 17:04
Show Gist options
  • Save jeepitou/4831c770344a8d5ad3b44972d5a8c076 to your computer and use it in GitHub Desktop.
Save jeepitou/4831c770344a8d5ad3b44972d5a8c076 to your computer and use it in GitHub Desktop.
A shell script to start tracking an Amazing Marvin task in Toggl Track.
#!/bin/bash
# -------------------------------------------------
# Before running the script, make sure that you understand it. Running code you find on the Internet may damage your system.
# -------------------------------------------------
# In Amazing marvin, set the path to this script as "Start time tracking task" in the "System Triggers strategy" like this:
# /Path/to/this/script $TASK_TITLE
# Replace "YourSecretToken" with your Toggl API token below.
# -------------------------------------------------
curl -v -u YourSecretToken:api_token \
-H "Content-Type: application/json" \
-d '{"time_entry":{"description":'"\"$1\""',"created_with":"curl"}}' \
-X POST https://api.track.toggl.com/api/v8/time_entries/start
# CODE BELOW IS FOR A SEPARATE FILE FOR THE "Stop time tracking task" trigger, which will stop the current timed task on Toggl.
#!/bin/bash
# -------------------------------------------------
# Before running the script, make sure that you understand it. Running code you find on the Internet may damage your system.
# -------------------------------------------------
# In Amazing marvin, set the path to this script as "Start time tracking task" in the "System Triggers strategy" like this:
# /Path/to/this/script
# Replace "YourSecretToken" with your Toggl API token below.
# -------------------------------------------------
current_entry=$(curl -v -u YourSecretToken:api_token -H "Content-Type: application/json" -X GET https://api.track.toggl.com/api/v8/time_entries/current)
entry_id=$(jq -n --argjson data "$current_entry" '$data.data.id')
curl -v -u YourSecretToken:api_token \
-H "Content-Type: application/json" \
-X PUT https://api.track.toggl.com/api/v8/time_entries/$entry_id/stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment