Skip to content

Instantly share code, notes, and snippets.

@gvvaughan
Created May 29, 2010 10:41
Show Gist options
  • Save gvvaughan/418199 to your computer and use it in GitHub Desktop.
Save gvvaughan/418199 to your computer and use it in GitHub Desktop.
TaskPaper TagAsDone.scpt
-- true if you want @done(YYYY-MM-DD), false if you want @done
property doneDates : true
-- save this script as an application to ~/Library/Application Support/TaskPaper/Scripts
-- and make (or copy from the system sounds) a "task done.aiff" file in the subdirectory:
-- "Tag as Done.app/Contents/Resources/"
set donefile to (path to me as string) & "Contents:Resources:task done.aiff" as alias
set donesound to quoted form of (POSIX path of (donefile as alias))
on getShortDate()
set now to (current date)
set {day:d, year:y, time:t} to now
-- Calculate the month number.
copy now to b
set b's month to January
set m to (b - 2500000 - now) div -2500000
-- Short date in yyyy-mm-dd format.
tell (y * 10000 + m * 100 + d) as string
set dateString to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end tell
return dateString
end getShortDate
set theDate to getShortDate()
tell application "TaskPaper"
set selected_entries to get selected entries
-- Iterate over selection to determine if we are adding or removing done tag
set add_done to false
repeat with each in selected_entries
tell each
if not (exists tag named "done") then
set add_done to true
end if
end tell
end repeat
-- Iterate over selection and add or remove done tag as needed
repeat with each in selected_entries
tell each
if add_done and not (exists tag named "done") then
if doneDates then
make tag with properties {name:"done", value:theDate}
else
make tag with properties {name:"done"}
end if
if exists tag named "today" then
delete tag named "today"
end if
do shell script ("afplay " & donesound & " > /dev/null 2>&1 &")
else if not add_done and (exists tag named "done") then
delete tag named "done"
end if
end tell
end repeat
end tell
@gvvaughan
Copy link
Author

I've called this 'Tag as Done' rather than 'Tag With Done' so that I can reassign the standard ⌘D shortcut using System Preferences.

The afplay binary is only available on Leopard and Snow Leopard. If you need to play sounds from AppleScripts in 10.4 and earlier, google will turn up a sound library you can use instead of afplay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment