Created
May 5, 2015 23:49
-
-
Save kholodilov/f2c796fa184cd835bc4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "OmniFocus" | |
tell front window | |
set selectedItems to value of selected trees of content | |
set theKey to (do shell script "defaults read io.postach.kholodilov 'rescuetime.api.key'") | |
repeat with theTask in selectedItems | |
set theName to get name of theTask | |
if (get parent task of theTask) is not missing value then | |
set theProject to get name of containing project of theTask | |
if (get context of theTask) is not missing value then | |
set theContext to ("@" & (get name of context of theTask)) | |
else | |
set theContext to "" | |
end if | |
set theEntry to ("[" & theProject & "] " & theName & " " & theContext) | |
set theSource to "" | |
else | |
set theEntry to theName | |
set theSource to "Projects" | |
end if | |
set theDate to get completion date of theTask | |
if theDate is missing value then | |
set theDate to current date | |
end if | |
set theDate to (my ISOformat(theDate)) | |
set escapedEntry to (do shell script "/bin/echo " & quoted form of theEntry & " | perl -MURI::Escape -lne 'print uri_escape($_)'") | |
set theURL to "https://www.rescuetime.com/anapi/highlights_post?key=" & theKey & "&highlight_date=" & theDate & "&description=" & escapedEntry & "&source=" & theSource | |
log theURL | |
do shell script "curl -X POST " & quoted form of theURL | |
end repeat | |
end tell | |
end tell | |
on ISOformat(theDate) | |
set y to text -4 thru -1 of ("0000" & (year of theDate)) | |
set m to text -2 thru -1 of ("00" & ((month of theDate) as integer)) | |
set d to text -2 thru -1 of ("00" & (day of theDate)) | |
return y & "-" & m & "-" & d | |
end ISOformat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment