Skip to content

Instantly share code, notes, and snippets.

@nickpascucci
Created July 21, 2017 02:31
Show Gist options
  • Select an option

  • Save nickpascucci/e6216f4f7aa256577cb0138dac79a47b to your computer and use it in GitHub Desktop.

Select an option

Save nickpascucci/e6216f4f7aa256577cb0138dac79a47b to your computer and use it in GitHub Desktop.

Revisions

  1. nickpascucci created this gist Jul 21, 2017.
    52 changes: 52 additions & 0 deletions of-completed.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    set ofPerspective to "Today" -- exact Perspective name

    set bmAuthToken to "<token>"
    set bmUser to "nickpascucci"
    set bmGoal to "intentions"

    set emailRecipient to "[email protected]"

    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