Tyme Scripting

Tyme is fully scriptable via AppleScript (or Javascript on Yosemite).

To view the AppleScript commands Tyme supports, start the AppleScript Editor, then drag Tyme.app onto the editor’s dock icon. If you find errors in any of the scripting object or you have an additional feature wish, please let us know. If you’ve written some useful scripts, please share it with us. We’ll post a collection of scripts here on the Tyme website.

Script Examples:

 

Start / stop the tracker:

tell application "Tyme"
  set p to the first item of (every project whose name = "Mein Projekt")
  set t to the first item of (every task of p whose name = "Meine Aufgabe")
  # starts the tracker
  set trackedTask to t
  delay 10
  # stops the tracker
  delete trackedTask
end tell

Create a new time session:

tell application "Tyme"
  make new timeSession with properties {timeStart:(current date) - 3600, timeEnd:(current date), note:"blah"} at the end of timeSessions of task 1 of project 1
end tell

Create a new project:

tell application "Tyme"
  make new project with properties {name:"NewProject", archived:false, dueDate:(current date)}
end tell

List all revenues made for a project:

tell application "Tyme"
  revenue of every timeSession of every task of project 1
end tell

Export data of the last 30 days as PDF and mail it to a recipient:

tell application "Tyme"
  set ex to make new export
  set startDate of ex to (current date) - 30 * days
  set endDate of ex to (current date)
  set exportFormat of ex to pdf
  set exportSorting of ex to time sort
  set showStartAndEndTimes of ex to true
  set showDurationInPercent of ex to false
  set showRevenue of ex to true
  set showNotes of ex to true
  set projectID of ex to (id of project 1)
  # The export folder is your 'Download' folder:
  set exportFileName of ex to "blah.pdf"
  save export ex
end tell

tell application "Mail"
  set theSubject to "Subject"
  set theContent to "Content"
  set theAddress to "some@receiver.com"
  set theAttachmentFile to "Macintosh HD:Users:lars:Downloads:blah.pdf"
	
  set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
  tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
  tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
	
  send msg
end tell

Script Hooks:

 

Tyme also has a few scripting hooks. For example you can trigger an AppleScript, when a new time session is created or you started or stopped a timer. For example you could mark a todo as completed in ToDoIst or Omnifocus. Also you could write an Alfred workflow to automate other things in Tyme. Writing your own scripts that react to these events is easy, just create a new scripting file named “tyme_applescript_hooks.scpt” in this folder “~/Library/Application Scripts/de.nulldesign.tyme.osx/” (you might need to create it, if it doesn’t exist) and copy & paste these methods:

on timeSessionCreated(timeSessionID)
	tell application "Tyme"
		set blah to revenue of lastCreatedTimeSession
		say "You just made " & blah & "bucks"
	end tell
end timeSessionCreated

on timerStarted(tskID)
	tell application "Tyme"
		set blah to name of trackedTask
		say "Active task is now " & blah
	end tell
end timerStarted

on timerStopped(tskID)
	say "timer stopped for task with id " & tskID
end timerStopped

on timeoutDetected(tskID)
	say "timeout for task with id " & tskID
end timeoutDetected

on projectCompletedChanged(projectID)
	set completedProjectID to projectID
	tell application "Tyme"
		set projectList to every project whose id = completedProjectID
		set completedProject to item 1 of projectList
		if archived of completedProject is true then
			tell application "Spotify"
				play track "spotify:track:3lZpRrikvXTFli0qyU7Q9q"
			end tell
		end if
	end tell
end projectCompletedChanged

on taskCompletedChanged(tskID)
	say "completed changed for task with id " & tskID
end taskCompletedChanged