Last active
February 26, 2020 13:59
-
-
Save fakeheal/7f17a22c73787bf6a3b62a4c45905789 to your computer and use it in GitHub Desktop.
AppleScript for returning total productivity time for the current day tracked by Rescue Time
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 "JSON Helper" | |
-- Set your api key here | |
-- You can get it at: https://www.rescuetime.com/anapi/manage | |
set rescuetime_api_key to "" | |
set {year:y, month:m, day:d} to (current date) | |
set today to y & "-" & m & "-" & d | |
set rescuetime to fetch JSON from "https://www.rescuetime.com/anapi/data?key="& rescuetime_api_key &"&format=json&restrict_begin=" & today & "&restrict_end=" & today | |
set rows to rows of rescuetime as list | |
set total_seconds to 0 | |
repeat with a from 1 to length of rows | |
set current_row to item a of rows | |
set productivity to item 6 of current_row | |
if productivity is greater than 1 then | |
set total_seconds to total_seconds + (item 2 of current_row) | |
end if | |
end repeat | |
if total_seconds > 0 | |
set command to "date -r" & total_seconds & " +'%Hh %Mm %Ss'" | |
set formatted_time to do shell script command | |
else | |
set formatted_time to "" | |
end if | |
return formatted_time | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment