AppleScript to stop Harvest Timer

I use Harvest for time tracking.

Also, I use Bunch. Almost all of my bunches start a Harvest timer. I want to stop the current timer when I close the bunch.

This is an excerpt of my Blog bunch.

...
..
.

* ~/Library/Scripts/Harvest.scpt "SAC" "Writing" "Writing post"  ~5

!<<#On Close
___
#[On Close]
* ~/Library/Scripts/Stop\ Harvest.scpt

Unfortunately, Harvest does not integrate with AppleScript. Moreover, they don't have a menu option to stop the current timer. Neither, a Keyboard Shortcut to stop the current timer. You can stop the the timer by click the H in the menu item but I am not sure I an automate that.

Thus, I resort to browser automation. The following AppleScript:

  • Opens Safari
  • Creates new tab and navigates to my harvest account.
  • Clicks the current timer stop button via Javascript.
set website to "https://softamo.harvestapp.com/time"
set theScript to "document.getElementsByClassName('js-stop-timer')[0].click();"
tell application "Safari"
    tell window 1
        set current tab to (make new tab with properties {URL:website})
    end tell
    delay 5
    do JavaScript theScript in current tab of first window
end tell

Tags: #automation #applescript #harvest #bunch #javascript