Created
July 21, 2017 02:31
-
-
Save nickpascucci/e6216f4f7aa256577cb0138dac79a47b to your computer and use it in GitHub Desktop.
AppleScript for sending OmniFocus stats to Beeminder
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
set ofPerspective to "Today" -- exact Perspective name | |
set bmAuthToken to "<token>" | |
set bmUser to "nickpascucci" | |
set bmGoal to "intentions" | |
set emailRecipient to "example@gmail.com" | |
set theDate to date string of (current date) | |
set reportTitle to "'" & ofPerspective & "' Tasks - " & theDate | |
set reportText to "# " & reportTitle & return | |
set emailSubject to "Report: " & reportTitle | |
tell front document of application "OmniFocus" | |
tell front document window | |
set perspective name to ofPerspective | |
set TaskList to value of (leaves of content) | |
set numTasks to (count of TaskList) | |
repeat with i from 1 to numTasks | |
set oTask to (item i of TaskList) | |
set oProject to (containing project of oTask) | |
set Reporttext to (Reporttext & "+ " & name of oProject & ": " & name of oTask as text) & return | |
end repeat | |
end tell | |
end tell | |
set reportFile to open for access "/tmp/report.md" with write permission | |
set eof of reportFile to 0 -- Truncate the file | |
write Reporttext to reportFile | |
close access reportFile | |
set ReportHtml to (do shell script "/usr/local/bin/markdown /tmp/report.md") | |
tell application "Airmail 3" | |
set email to make new outgoing message with properties {subject:emailSubject} | |
set htmlContent of email to ReportHtml | |
make new to recipient at end of email's to recipients with properties {name:"", address:emailRecipient} | |
compose email | |
activate | |
end tell | |
set baseUrl to "https://www.beeminder.com/api/v1/users/" & bmUser & "/goals/" | |
set intentionsUrl to baseUrl & bmGoal & "/datapoints.json?value=1" & "&comment=" & numTasks & "%20Flagged%20OmniFocus%20tasks&auth_token=" & bmAuthToken | |
-- URL must be in quotes to prevent bash from interpreting & symbols. | |
set curlCommand to "curl -d '' '" & intentionsUrl & "'" | |
display alert "Send data to Beeminder?" buttons {"No", "Yes"} | |
if button returned of result = "Yes" then | |
do shell script curlCommand | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment