View Single Post
Quote:
Originally Posted by skillet View Post
I plan on posting an update when I am able to work this out.
Ok I didn't work this out whpalmer4 did in post 8

It's even better than I thought it could be. It works on multiple actions and doesn't need to check if actions are repeating since it duplicates them and removes the repeat and flag. Here's the AppleScript he compiled.

Code:
--*** This script uses four scripts combined
-- Some code from Dan Byler's "Snooze" script
(* 	# LICENSE #
	
	Copyright © 2010 Dan Byler (contact: dbyler@gmail.com)
	Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
*)

--http://forums.omnigroup.com/showthread.php?p=101869#post101869 post 7 by scb	
--***Copy a list of selected tasks , or an individual task, to non repeating and remove flags if any. The original task is marked as completed.

property prependText : "[Follow-Up] "

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 : "OmniFocus.app"

tell application "OmniFocus"
	activate
	tell default document
		set FrontWindow to first document window whose index is 1
		tell FrontWindow
			
			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
			
			if ((count of leaves of selected trees of content) is 0) then
				set theItems to value of selected trees of content
			else
				set theItems to (value of leaves of selected trees of content) as list
			end if
			
			set successTot to 0
			repeat with anItem in theItems
				if (class of anItem) is list then
					repeat with subItem in anItem
						if (class of subItem is task or class of subItem is inbox task) then
							
							set newitem to duplicate subItem to after subItem
							set repetition of newitem to missing value
							set flagged of newitem to false
							set completed of subItem to true
							set name of subItem to prependText & name of subItem
							set succeeded to my snooze(newitem, todayStart, snoozeLength)
							if succeeded then set successTot to successTot + 1
							
						end if
					end repeat
					
				else if (class of anItem is task or class of anItem is inbox task) then
					set newitem to duplicate anItem to after anItem
					set repetition of newitem to missing value
					set flagged of newitem to false
					set completed of anItem to true
					set name of anItem to prependText & name of anItem
					set succeeded to my snooze(newitem, todayStart, snoozeLength)
					if succeeded then set successTot to successTot + 1
					
				end if
			end repeat
			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
			my notify(alertName, alertTitle, alertText)
		end tell
	end tell
end tell


-- ***Now change only the start date from absolute date (today's date) and not relative date.  Keep due date the same since that doesn't typically change (if so I would change that by hand or with another Dan's defer script)

--***The only thing I would change about this is to keep the start time (but not date) the same as it was, and not change it to 12AM like this script does.  I really like that it moves it from today's date because that way I know the exact date all the selected actions will be on.

on snooze(selectedItem, todayStart, snoozeLength)
	set success to false
	tell application "OmniFocus"
		try
			set oldStart to start date of selectedItem
			set daysBetween to (todayStart - oldStart) / days as integer -- compute # of full days between orig start date+time and start of today
			-- new start is old start + daysBetween + snooze + 1 (because snoozeLength 1 means starts tomorrow, not today)
			set newStart to oldStart + (days * (daysBetween + 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
		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 "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
		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