Friday, February 12, 2010

DWM AppleScripts

I've been experimenting with new time management systems from Mark Forster, first trying Autofocus v. 4 and now DWM. I've found AF4 to be quite nice over the last few weeks, and like what I've seen of DWM over the last few days. In each case, I've used iCal to manage the tasks in the system.

With DWM, I keep my at-home tasks as iCal todos on a separate calendar (my work tasks are still in AF4, but will be switched over soon). Each todo has a due date; the due date here doesn't mean "do on this date," but instead means "do by this date." I keep the tasks sorted by due date. For tasks that really must be done on a particular date, put them on a different calendar, and they'll appear at the top of the list on that due date. This works well, but it is a little annoying to regularly set the due dates by hand.

The todos are set with a regular pattern, to either the next week or the next month. This is scriptable. Here is the next-week script, which I saved as "To Do Within 7 Days" under the iCal application scripts:
setDueDate of (7*days) for selectedToDo()

to setDueDate of timeFrame for task
set newDate to (current date) + timeFrame
tell application "iCal" to set due date of task to newDate
end setDueDate

on selectedToDo()
set referenceText to iCalSelectionText at 1
tell application "iCal"
repeat with cal in calendars
set matches to (todos of cal where summary is equal to referenceText)
if (count of matches) > 0 then
exit repeat
end if
end repeat
if (count of matches) is equal to 0 then
error "No matching to-do item found."
end if
first item of matches
end tell
end selectedToDo

on iCalSelectionText at timeDelay
set the oldClipboard to the clipboard
copyICalSelection at timeDelay
set selectionText to the clipboard
on error errText number errNum
set the clipboard to the oldClipboard
error errText number errNum
end try
set the clipboard to the oldClipboard
end iCalSelectionText

on copyICalSelection at timeDelay
tell application "iCal" to activate
tell application "System Events"
tell process "iCal"
keystroke return
keystroke "c" using {command down}
keystroke return
end tell
end tell
delay timeDelay
end copyICalSelection

The next-month script is similar, just replace the 7*days by 30*days.

The bulk of the script, and the only thing tricky about it, is getting a selected to-do item; the iCal scripting dictionary provides no way to do this! The handlers selectedToDo, iCalSelectionText, and copyICalSelection are a work around. I didn't come up with this approach, it comes from a Mac OS X Hints contributor.

Overall, I'm liking DWM a lot, but I doubt I'd like it without the scripts. Because of the nature of the system, I'll make no recommendation either for or against using DWM until a month has passed, but I already do think it is quite interesting and worth taking a look at.

Update: You can download compiled scripts here.

No comments: