Last active
August 29, 2015 14:18
-
-
Save kenjitayama/526ed1f71363b08ba647 to your computer and use it in GitHub Desktop.
For OmniFocus2. Toggle flagged/completed of selected tasks and log to file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
# DESCRIPTION # | |
Toggle flagged/completed of selected tasks and log to file. | |
*) | |
on main() | |
-- constants start | |
set toggleTypeFlagged to "flagged" | |
set toggleTypeCompleted to "completed" | |
-- constants end | |
-- settings start | |
set logdir to do shell script "echo ~/Documents/omnifocus_tasklog/`date +%Y`/`date +%Y-%m`/`date +%Y-%m-%d`" | |
set logfile to logdir & "/" & do shell script "echo omnifocus_tasklog_`date +%Y-%m-%d`.txt" | |
set toggleType to toggleTypeFlagged | |
--set toggleType to toggleTypeCompleted | |
-- settings end | |
do shell script "mkdir -p " & logdir | |
tell application "OmniFocus" | |
tell content of first document window of front document | |
--Get selection | |
set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder) | |
set totalItems to count of validSelectedItemsList | |
if totalItems is 0 then | |
my notify("No valid task(s) selected") | |
return | |
end if | |
repeat with thisItem in validSelectedItemsList | |
if toggleType is equal to toggleTypeFlagged then | |
set isFlagged to my toggleFlag(thisItem) | |
my logFlag(thisItem, isFlagged, logfile) | |
else if toggleType is equal to toggleTypeCompleted then | |
set isDone to my toggleDone(thisItem) | |
my logDone(thisItem, isDone, logfile) | |
end if | |
end repeat | |
end tell | |
end tell | |
end main | |
on toggleFlag(selectedItem) | |
set isFlagged to flagged of selectedItem | |
set flagged of selectedItem to not isFlagged | |
return flagged of selectedItem | |
end toggleFlag | |
on toggleDone(selectedItem) | |
set isDone to completed of selectedItem | |
set completed of selectedItem to not isDone | |
return completed of selectedItem | |
end | |
on logFlag(selectedItem, isFlagged, logfile) | |
if flagged of selectedItem is true then | |
set actionStr to "+flag" | |
else | |
set actionStr to "-flag" | |
end if | |
logTask(selectedItem, actionStr, logfile) | |
end | |
on logDone(selectedItem, isDone, logfile) | |
if completion date of selectedItem is not missing value then | |
set actionStr to "+done" | |
else | |
set actionStr to "-done" | |
end if | |
logTask(selectedItem, actionStr, logfile) | |
end | |
on logTask(selectedItem, actionStr, logfile) | |
set taskProject to containing project of selectedItem | |
set projectName to "" | |
if taskProject is not missing value then | |
set projectName to name of taskProject | |
end if | |
set taskName to name of selectedItem | |
set logStr to actionStr & "\t" & projectName & "\t" & taskName | |
set echoStr to "`date +%Y-%m-%d\\ %H:%M:%S`" & "\t" & logStr | |
set cmdStr to "echo \"" & echoStr & "\" >> " & logfile | |
do shell script cmdStr | |
end logTask | |
on notify(alertText) | |
tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK" | |
end notify | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment