The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Today's Posts

 
Select All Actions Created In The Last 2 Seconds Thread Tools Search this Thread Display Modes
Ok here is an update, it still doesn't solve the toggling problem of actions that have a start date tomorrow 12PM and later from going to today if you choose to start in one day from now. This update will make it start today rather than keep it the same of tomorrow like it should.

The update does start the actions for morning actions and after noon actions by the right time (other than the hicup mentioned above).

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 : "[In Progress] "

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)
			
			
			if daysBetween is less than 43201 then
				
				
				set newStartMorning to oldStart + (days * (daysBetween + snoozeLength))
				set start date of selectedItem to newStartMorning
				
			else
				
				set newStartMorning to oldStart + (days * (daysBetween + snoozeLength + 1))
				set start date of selectedItem to newStartAfternoon
			end if
			
			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
 
Improved version of the routine that adjusts the start date/time:

Code:
on snooze(selectedItem, todayStart, snoozeLength)
	set success to false
	tell application "OmniFocus"
		try
			set oldStart to start date of selectedItem
			if (oldStart is missing value) then
				set oldStart to todayStart -- no start date, pretend it was start of today
			end if
			set fracDay to time of oldStart
			set start date of selectedItem to todayStart + fracDay + (days * snoozeLength)
			set success to true
		end try
	end tell
	return success
end snooze
 
Nice work, I sure couldn't have done that on my own!

When I run it on multiple actions and set it say beyond 1 day in the future and then run it again and set it to 1 day in the future I get an error "Can't get tree 2 of tree 3". With three actions selected in this case it only changes the first selected action to the correct start time 1 day from now. Not a big deal because if I run it again it will then work just fine.

I hope to some day to know a fraction of what you know. I have spent the past 4 hours going through the Script Debugger tutorial and seeing what I can learn from it to help me on my AS quest. Hopefully I won't be such a beggar and can help others out.
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2011-09-20 at 3.54.42 PM.jpg
Views:	470
Size:	167.2 KB
ID:	2030   Click image for larger version

Name:	Screen shot 2011-09-20 at 3.53.29 PM.png
Views:	468
Size:	156.8 KB
ID:	2031  

Last edited by skillet; 2011-09-20 at 12:07 PM..
 
Quote:
Originally Posted by skillet View Post
When I run it on multiple actions and set it say beyond 1 day in the future and then run it again and set it to 1 day in the future I get an error "Can't get tree 2 of tree 3". With three actions selected in this case it only changes the first selected action to the correct start time 1 day from now. Not a big deal because if I run it again it will then work just fine.
Not only is that not my code, it doesn't even appear in my script :-)
 
Quote:
Originally Posted by whpalmer4 View Post
Not only is that not my code, it doesn't even appear in my script :-)
Oh boy, I'm a fool [blush]! I took the part that forwarded start times and had been using it with the old script that just forwarded start dates. Just testing out that part so I didn't have to go through the duplicate process and all the other things it did for the test. Plus I want to use that part as a stand alone script as well (i.e.with out duplicating actions and prepending text).

Thanks for the smile and not giving me a frown like I deserve. It must be hard dealing with subpar mortals. Thanks for your patience and sorry to waste your time on that one :(.
Attached Files
File Type: zip Snooze Start - From Today - Relative Time.scpt.zip (11.6 KB, 426 views)

Last edited by skillet; 2011-12-29 at 04:01 PM..
 
Just wanted to say thanks again whpalmer4, I have used this script almost every day for the past three months. It has also helped me with other scripts I modified.

There are two attached actions "Prepend Text on Completed Action" is just the script from Bill to download as a script. And "Prepend Text on Completed and New Action" combines two of Bill's scripts to prepend text to the completed action and new action.

Be aware that if you run "Prepend Text on Completed and New Action" on more than 2 actions it will probably not add the prepended text to the duplicated action since it will have been longer than 5 seconds since it was created. I didn't want to make it longer since it might select actions that you created by hand before you run the script and then it prepends text to that rather than just the duplicate.

I am sure there is a more elegant way to do this by adding the prepend text to the duplicated right after it is created but haven't figured that out yet.

Not quite sure why it doesn't prepend text to the newly created action that was made because of the repeating action being marked as complete (even if it is set to 100 seconds) but that is the behavior I was after anyway, so that is nice. As you can see from the picture "Test 1" duplicate action didn't receive any prepended text because it was created longer than 5 seconds earlier when run on more than two actions (feel free to increase the time interval).

You can download it from here with icons (478KB was too large to upload to this site).
http://reference.Studioprime.com/for...Up_Actions.zip
Attached Thumbnails
Click image for larger version

Name:	Prepend Text on Completed and New Action - Before.png
Views:	499
Size:	124.7 KB
ID:	2163   Click image for larger version

Name:	Prepend Text on Completed and New Action - After.png
Views:	498
Size:	94.6 KB
ID:	2164  
Attached Files
File Type: zip Follow-Up_Actions.zip (36.2 KB, 423 views)

Last edited by skillet; 2011-12-29 at 04:47 PM..
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
No To-Dos created for Projects? aigeanta iCal Sync 2 2010-11-17 06:46 PM
Not seeing Actions created through Email rule dpowers OmniFocus 1 for Mac 3 2009-12-01 09:11 AM
70 seconds to launch & sync :: Help! geekylucas OmniFocus Syncing 6 2008-08-28 09:44 PM
Min:Seconds in duration column? MichaelShapiro OmniOutliner 3 for Mac 2 2008-04-11 02:03 AM
Close download window after X seconds revs OmniWeb Feature Requests 1 2006-06-20 02:21 PM


All times are GMT -8. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.