I’ve made good use of Dan Byler’s OF scripts and appreciate them very much. http://bylr.net/files/omnifocus/
I want to to modify his CLEAR DATES script (which has an option to CHANGE the context) in such a way that it will REMOVE the context from an item, not just change it to something else. I often remove contexts from items to take them out of play for a day’s work.
How would I adjust the following code to have the context REMOVED from selected items when the script is run?
-- To change settings, modify the following properties
property showAlert : false --if true, will display success/failure alerts
property useGrowl : true --if true (and showAlert is true), uses Growl for alerts
property changeContext : true --true/false; if true, set newContextName (below)
property newContextName : “Someday” --context the item will change to if changeContext = true
– Don’t change these
property alertItemNum : “”
property alertDayNum : “”
property dueDate : “”
property growlAppName : “Dan’s Scripts”
property allNotifications : {“General”, “Error”}
property enabledNotifications : {“General”, “Error”}
property iconApplication : “OmniFocus.app”
tell application “OmniFocus”
tell front document
if changeContext then
set newContextID to id of item 1 of (complete newContextName as context) --new
set newContext to first context whose id is newContextID --new
end if
tell (first document window whose index is 1)
set theSelectedItems to selected trees of content
set numItems to (count items of theSelectedItems)
if numItems is 0 then
set alertName to “Error”
set alertTitle to “Script failure”
set alertText to “No valid task(s) selected”
my notify(alertName, alertTitle, alertText)
return
end if
set selectNum to numItems
set successTot to 0
set autosave to false
repeat while selectNum > 0
set selectedItem to value of item selectNum of theSelectedItems
if changeContext then
set context of selectedItem to newContext --new
end if
set succeeded to my clearDate(selectedItem)
if succeeded then set successTot to successTot + 1
set selectNum to selectNum - 1
end repeat
set autosave to true
set alertName to "General"
set alertTitle to "Script complete"
if successTot > 1 then set alertItemNum to "s"
set alertText to "Date(s) cleared for " & successTot & " item" & alertItemNum & "." as string
end tell
end tell
my notify(alertName, alertTitle, alertText)
end tell
on clearDate(selectedItem)
set success to false
tell application “OmniFocus”
try
log defer date of selectedItem
set defer date of selectedItem to missing value
set due date of selectedItem to missing value
set success to true
end try
end tell
return {success}
end clearDate
on notify(alertName, alertTitle, alertText)
if showAlert is false then
return
else if useGrowl is true then
–check to make sure Growl is running
tell application “System Events” to set GrowlRunning to ((application processes whose (name is equal to “GrowlHelperApp”)) count)
if GrowlRunning = 0 then
–try to activate Growl
try
do shell script “/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &”
do shell script “~/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &”
end try
delay 0.2
tell application “System Events” to set GrowlRunning to ((application processes whose (name is equal to “GrowlHelperApp”)) count)
end if
–notify
if GrowlRunning ≥ 1 then
try
tell application “Growl”
register as application growlAppName all notifications allNotifications default notifications allNotifications icon of application iconApplication
notify with name alertName title alertTitle application name growlAppName description alertText
end tell
end try
else
set alertText to alertText & "
p.s. Don’t worry—the Growl notification failed but the script was successful."
display dialog alertText with icon 1
end if
else
display dialog alertText with icon 1
end if
end notify