View Single Post
Originally Posted by whpalmer4 View Post
Though now that someone finally wrote this script maybe I'll start using it :-)
Let me know how you like it ;)

I spent about 4 hours today trying to write a script that worked on multiple selected actions and...
1) would not run if there is any repeating actions selected.
2) duplicate selected actions.
3) mark them as [In Progress] in the action name.
4) mark them as complete.
5) select the original actions (I might have to do this on only one action at a time because of this).
6) forward only the start dates from today's date by a given amount. Not the original start date if it was say yesterday.

This script does step 6 but unfortunately it does not keep the original start time.

	This script "snoozes" the currently selected actions or projects by setting the start date to given number of days in the future.
	Copyright © 2010 Dan Byler (contact:
	Licensed under MIT License (
	0.2c (2010-06-22)
	-	Actual fix for autosave
	0.2b (2010-06-21)
	-	Encapsulated autosave in "try" statements in case this fails
	0.2 (2010-06-15)
	-	Fixed Growl code
	-	Added performance optimization (thanks, Curt Clifton)
	-	Changed from LGPL to MIT license (MIT is less restrictive)
	0.1: Original release. (Thanks to Curt Clifton, Nanovivid, and Macfaninpdx for various pieces of code)

	-	Copy to ~/Library/Scripts/Applications/Omnifocus
 	-	If desired, add to the OmniFocus toolbar using View > Customize Toolbar... within OmniFocus

	-	When the script is invoked from the OmniFocus toolbar and canceled, OmniFocus returns an error. This issue does not occur when invoked from the script menu, a FastScripts or Quicksilver trigger, etc.

property showAlert : false --if true, will display success/failure alerts
property useGrowl : true --if true, will use Growl for success/failure alerts
property defaultSnooze : 1 --number of days to snooze by default
property alertItemNum : ""
property alertDayNum : ""
property growlAppName : "Dan's Scripts"
property allNotifications : {"General", "Error"}
property enabledNotifications : {"General", "Error"}
property iconApplication : ""

tell application "OmniFocus"
	tell front document
		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)
			end if
			display dialog "Snooze start date for how many days from today?" default answer defaultSnooze buttons {"Cancel", "OK"} default button 2
			set snoozeLength to (the text returned of the result) as integer
			set todayStart to (current date) - (get time of (current date))
			if snoozeLength is not 1 then
				set alertDayNum to "s"
			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
				set succeeded to my snooze(selectedItem, todayStart, snoozeLength)
				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 successTot & " item" & alertItemNum & " snoozed. The item" & alertItemNum & " will become available in " & snoozeLength & " day" & alertDayNum & "." as string
		end tell
	end tell
	my notify(alertName, alertTitle, alertText)
end tell

on snooze(selectedItem, todayStart, snoozeLength)
	set success to false
	tell application "OmniFocus"
			set newStart to (todayStart + (86400 * snoozeLength))
			set start date of selectedItem to newStart
			set success to true
		end try
	end tell
	return success
end snooze

on notify(alertName, alertTitle, alertText)
	if showAlert is false then
	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
				do shell script "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/ > /dev/null 2>&1 &"
				do shell script "~/Library/PreferencePanes/Growl.prefPane/Contents/Resources/ > /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
		if GrowlRunning ≥ 1 then
				tell application "GrowlHelperApp"
					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
			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
		display dialog alertText with icon 1
	end if
end notify

I downloaded Script Debugger like you use Bill and that was helpful. I was able to modify your scripts.
1) get it to check if actions had a repeat so it wouldn't run if they did.
2) Forward only the start date (sadly not from today's date but from the original start date but at least it kept the same start time).
3) Marked the actions as complete.

Still need to figure out how to get it to work with your append text to action name and how to duplicate a non repeating action if that is even possible.

*UPDATE: Found this forum for how to duplicate a non repeating action.

I plan on posting an update when I am able to work this out.

Originally Posted by whpalmer4 View Post

Onomatopoeic :-)
Nice that is good! Thanks for a new word in my vocabulary, now if only I can remember that in the future.

Originally Posted by whpalmer4 View Post

Is "Task" different than "task" in Applescript? In all cases? No such worries with "oTask"! I think I've probably read more of Rob's Applescript than anyone else's, so some of his style may have rubbed off on me, especially the part about writing scripts for others instead of focusing on one's own work at times :-)
That makes sense thanks for the tip.

Last edited by skillet; 2011-09-17 at 03:33 AM..