Skip to content

Instantly share code, notes, and snippets.

@tianhao
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save tianhao/1dea9b4eae7cfe809d8a to your computer and use it in GitHub Desktop.

Select an option

Save tianhao/1dea9b4eae7cfe809d8a to your computer and use it in GitHub Desktop.
(*
This script allows to start timer of TimeLog with current selected
task in OmniFocus. The OmniFocus part of this script belongs to
Andrew Berry (andrewberry@sentex.net), who created it for task
tracking in OmniOutliner.
Trim function is borrowed somewhere else =)
In the shown dialog category in terms of TimeLog is separated
from Project with ">" sign.
This task is started in default calendar of TimeLog. Cause
I didn't find out how to select the calendar =(
Know bugs & issues:
1) Can't process tasks from Inbox
(c) Alex Kudryashov 2011
*)
on trim(someText)
repeat until someText does not start with " "
set someText to text 2 thru -1 of someText
end repeat
repeat until someText does not end with " "
set someText to text 1 thru -2 of someText
end repeat
return someText
end trim
tell application "OmniFocus"
tell front document
tell document window 1
set theSelectedItems to selected trees of content
if ((count of theSelectedItems) < 1) then
display alert "You must first select a single task." message "Select a single task before running this script." as warning
return
end if
if ((count of theSelectedItems) > 1) then
display alert "You must select only one task." message "Select a single task before running this script." as warning
return
end if
end tell
end tell
set theDoc to document window 1 of document 1
set theSelectedTask to value of item 1 of theSelectedItems
set taskProject to (containing project of theSelectedTask)
set projectName to (name of taskProject)
set taskName to (name of theSelectedTask)
set temp to display dialog "Category > Project" default answer taskName & " > " & projectName
set text_user_entered to the text returned of temp
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {">"}
set inCategoryRaw to the first text item of text_user_entered
set inProjectRaw to the second text item of text_user_entered
set inCategory to my trim(inCategoryRaw)
set inProject to my trim(inProjectRaw)
set AppleScript's text item delimiters to old_delimiters
set encCategory to do shell script "php -r 'echo trim(rawurlencode(\"" & inCategory & "\"));'"
set encProject to do shell script "php -r 'echo trim(rawurlencode(\"" & inProject & "\"));'"
set finalLink to "timelog://start/?project=" & encProject & "&client=Alexander%20Kudryashov&category=" & encCategory & ""
end tell
tell application "TimeLog" to activate
tell application "Finder"
set visible of process "TimeLog" to false
end tell
open location finalLink
activate application "OmniFocus"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment