Scripting Tyme

Tyme is fully scriptable via AppleScript (or JavaScript). To view the AppleScript commands Tyme supports, start the AppleScript Editor, then drag Tyme2.app onto the editor’s dock icon. The following examples show how you can create projects, tasks and time entries:

// starting a timer
StartTrackerForTaskID "B98A6E...221CC252"

// listing active task ids
trackedTaskIDs

// stopping a timer
StopTrackerForTaskID "B98A6E6E...5221CC252"

// creating a project
make new project with properties {name:"A", defaultHourlyRate:120.0, dueDate:(current date), plannedBudget:1000.0, plannedDuration:60.0}

// searching for a project
set p to the first item of (every project whose name = "A")
name of p

// creating a task
make new task with properties {name:"B", taskType:"timed", dueDate:(current date), timedRoundingMinutes:30, timedHourlyRate:75.0} at the end of tasks of p

// searching for a task
set t to the first item of (every task of every project whose name = "B")
name of t

// creating a new time record
make new taskRecord with properties {recordType:"timed", timeStart:today - 60 * 18, note:"Hello World!"} at the end of taskRecords of t

set r to the first item of taskRecords of t
note of r

// creating a new mileage record
make new task with properties {name:"C", taskType:"mileage", mileageKilometerRate:0.4} at the end of tasks of p

set m to the first item of (every task of every project whose name = "C")
name of m

// creating fixed costs
make new task with properties {name:"D", taskType:"fixed", fixedRate:4.99, fixedQuantity:3} at the end of tasks of p

set f to the first item of (every task of every project whose name = "D")
name of f

Write your own exporter using a get task records command with various options:

GetTaskRecordIDs startDate ((current date) - 36000) endDate (current date) categoryID "B98A6E6E..001F35221CC252" with onlyBillable
 
set fetchedRecords to fetchedTaskRecordIDs as list
// loop through all fetched records
repeat with recordID in fetchedRecords
   GetRecordWithID recordID
   timedDuration of lastFetchedTaskRecord
   ... // write the record anywhere
end repeat

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 “tyme2_applescript_hooks.scpt” in this folder “~/Library/Application Scripts/de.lgerckens.Tyme2/” (if it’s not there, create it).

You need to implement the following methods:

on timerStartedForTaskRecord(tskRecordID)
 tell application "Tyme2"
 GetRecordWithID tskRecordID
 set tskID to relatedTaskID of lastFetchedTaskRecord
 set tsk to the first item of (every task of every project whose id = tskID)
 set tskName to name of tsk
 say tskName
 end tell
end timerStartedForTaskRecord

on timerStoppedForTaskRecord(tskRecordID)
 tell application "Tyme2"
 GetRecordWithID tskRecordID
 if recordType of lastFetchedTaskRecord is equal to "timed" then
 set d to timedDuration of lastFetchedTaskRecord
 say d
 end if
 end tell
end timerStoppedForTaskRecord

on timeoutDetectedForTaskRecord(tskRecordID)
 tell application "Tyme2"
 GetRecordWithID tskRecordID
 set tskID to relatedTaskID of lastFetchedTaskRecord
 set tsk to the first item of (every task of every project whose id = tskID)
 set tskName to name of tsk
 say tskName
 end tell
end timeoutDetectedForTaskRecord

on projectCompletedChanged(projectID)
 tell application "Tyme2"
 set prj to the first item of (every project whose id = projectID)
 set prjName to name of prj
 say prjName
 end tell
end projectCompletedChanged

on taskCompletedChanged(tskID)
 tell application "Tyme2"
 set tsk to the first item of (every task of every project whose id = tskID)
 set tskName to name of tsk
 say tskName
 end tell
end taskCompletedChanged