Skip to content

Instantly share code, notes, and snippets.

@selfire1
Created June 17, 2021 09:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save selfire1/1107941a0e74e1fe87bd460091956e4f to your computer and use it in GitHub Desktop.
Save selfire1/1107941a0e74e1fe87bd460091956e4f 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
@jeepitou
Copy link

jeepitou commented Jun 17, 2021

Hey man thanks for you script that's super cool!
I've made a separate script for when you stop the timer. It's a bit slow since I need to get the current task being timed before I actually stop it. But it works.
It requires jq installed on the computer to work.

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

@selfire1
Copy link
Author

Awesome, that's super handy!

@Rom142G
Copy link

Rom142G commented Oct 15, 2022

Capture d’écran 2022-10-15 160618
I have a problem with the script in amazing marvin. I searched for a while on the internet and it talked about some npm stuff but I don’t know how to run it as I’m not familiar with coding in general.
Do you know how to solve my problem or could you help me ? Your scripts will certainly be beneficial for me : )

Thanks in advance for anyone who will respond ! ヾ(•ω•`)o

@jeepitou
Copy link

Hey @Rom142G,
I am not an expert in coding. But it seems like the directory you put in marvin has some mistakes in it. It appears without any / in the second line of your error message.

@Rom142G
Copy link

Rom142G commented Oct 17, 2022

I changed the directory and it’s the same error message that appears :/

In my marvin-toggl-tracking.sh file I have exactly this that is typed in (except for the ""#"" it’s just a #):

""#""!/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 {The token that I used}: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

In my triggers file in the Marvin folder I have this type in:
{
"onStartTimeTracking": "\C:\Users\User\Desktop $TASK_TITLE"
}

And finally, in Marvin I have this type in:
\C:\Users\User\Desktop $TASK_TITLE

I don’t know why Marvin double the slash bars when I copy paste them automatically, maybe that’s the issue.

I don’t really if these information is important for you but I want to provide you more information by hoping that you can help me solve this problem. : )

@jeepitou
Copy link

can you try using / instead of \ in Marvin?

@Rom142G
Copy link

Rom142G commented Oct 18, 2022

I tried with / in marvin and with \ in the triggers json file: the same message appeared
I tried with / in Marvin and with / in the triggers json file:
image
I tried with / in Marvin and with // in the triggers json file:
image

I don’t really know what to do, you didn’t have any issue with it before ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment