Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashtom/832005 to your computer and use it in GitHub Desktop.
Save ashtom/832005 to your computer and use it in GitHub Desktop.
-- OmniFocus to Pomodoro App for iPad
-- This script practically takes text that's on your clipboard
-- and generates a Pomodoro App for iPad compatible JSON file
-- for you to import in to the app (using Dropbox)
--
-- I'm using it with OmniFocus, where copied tasks remain
-- on the clipboard as lines of text, basically.
-- If you're stuck on Things and this script is not working,
-- NOW might be a good time to switch.
--
-- Created by Andreas on 2011-02-17
-- Changed by Thomas on 2011-02-17
--
set clipboardContent to the clipboard as text -- this is what we're working with
set clipboardContentLines to (count paragraphs of clipboardContent) - 1 -- get count of lines on clipboard
set estimateItems to {}
set JSONresult to ""
set JSONresults to {}
set JSONBeginning to "[\n"
set JSONEnd to "]"
set JSONTaskBegin to "\t{\n"
set JSONTaskEstimate to "\t\t\"estimate\":"
set JSONTaskEnd to "\t}\n"
set JSONTaskListEnd to "\t},\n"
set JSONTaskList to "\t\t\"list\":0,\n"
set JSONTaskTitle to "\t\t\"title\":\""
set UserName to do shell script "whoami"
set JSONfilename to "/Users/" & UserName & "/Dropbox/Pomodoro/tasks.json"
-- this routine displays a dialog where the user can set an estimate amount of pomodoros for each task on the clipboard
repeat with i from 1 to clipboardContentLines
set estimateDialog to display dialog "Estimate: " & (paragraph i of clipboardContent) default answer ¬
"2" buttons {"Cancel", "OK"} default button {"OK"}
if (button returned of estimateDialog is "OK") and (text returned of estimateDialog is not "") then
copy text returned of estimateDialog to the end of estimateItems
else if (button returned of estimateDialog is "OK") and (text returned of estimateDialog is "") then
set amount to "2" -- default estimate is 2
else if (button returned of estimateDialog is "Cancel") then
return
end if
end repeat
-- now we're stitching everything together
repeat with i from 1 to clipboardContentLines
if i is not equal to clipboardContentLines then -- last item needs to be handled differently. FU JSON!
set end of JSONresults to JSONTaskBegin & ¬
JSONTaskEstimate & (item i of estimateItems) & ",\n" & ¬
JSONTaskList & ¬
JSONTaskTitle & (paragraph i of clipboardContent) & "\"\n" & ¬
JSONTaskListEnd
else
set end of JSONresults to JSONTaskBegin & ¬
JSONTaskEstimate & (item i of estimateItems) & ",\n" & ¬
JSONTaskList & ¬
JSONTaskTitle & (paragraph i of clipboardContent) & "\"\n" & ¬
JSONTaskEnd
end if
end repeat
repeat with i from 1 to clipboardContentLines
set JSONresult to JSONresult & (item i of JSONresults)
end repeat
set JSONresult to JSONBeginning & JSONresult & JSONEnd
-- move exisiting files to old
set JSONpattern to "/Users/" & UserName & "/Dropbox/Pomodoro/*.json"
set fileMove to do shell script "for i in $(" & JSONpattern & "); do mv $i $i.old; done"
do shell script fileMove
-- write the results
set cmd to "echo " & (quoted form of JSONresult as string) & " > " & JSONfilename -- yeah, i know i suck for not using applescript here.
--return cmd
do shell script cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment