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 Search Today's Posts Mark Forums Read

 
Select All Actions Created In The Last 2 Seconds Thread Tools Search this Thread Display Modes
Is there a way to have OmniFocus select all actions created in the last one or two seconds but that are not repeating actions? I would imagine that might be difficult because not every view would show all the actions that may have just been created.

Not sure if this require something more advanced like Rob Trew's searchAll script.
 
A sample code fragment:
Code:
property pMaxAge : 2 -- max number of seconds since creation for tasks of interest
tell application "OmniFocus"
	set timeNow to current date
	set timeThen to timeNow - pMaxAge
	tell front document
		set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
			and repetition is missing value))
	end tell
	display alert "Found " & (count of newTasks) & " tasks"
end tell
 
Quote:
Originally Posted by whpalmer4 View Post
A sample code fragment:
Code:
property pMaxAge : 2 -- max number of seconds since creation for tasks of interest
tell application "OmniFocus"
	set timeNow to current date
	set timeThen to timeNow - pMaxAge
	tell front document
		set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
			and repetition is missing value))
	end tell
	display alert "Found " & (count of newTasks) & " tasks"
end tell

Man, I know too little to be able to write this script. I have searched through the forums since you posted this 3 hours ago looking for any action that selects actions and the only one that I can find is Where in OF.

Draft FAQ: OF 1.8 Filter options and their search-language equivalents seems like it has the answer but I can't make sense of it enough to cobble together a script.

I don't know if this is the most effective way but if there was a way to filter and show only actions added in the last two seconds then I could select all and process all those items with a new start date.

I'm so close to having a complete and glorious script I can taste it. Maybe Rob Trew can shed some light on this. Where in OF is makes me glaze over looking at it; It must have taken 6 months to write that!

Last edited by skillet; 2011-12-29 at 11:11 AM..
 
I'm not sure what you are asking, but that script that I included, when run, selects all the actions that have been created in the last two seconds; newTasks is a list containing them all. Instead of doing the "display alert" statement, you put your code there that does whatever it is you want to do with the tasks created in the last two seconds. What do you want to do?
 
For me it doesn't actually select newly created actions in Project View or in Context View.

See the video and maybe you can tell me what I am missing. The actions at the end of the video left in orange are the ones that are actually the newly created actions.

Sorry there is no audio with the video.
http://dl.dropbox.com/u/3835246/OFSe...ded/index.html
 
No, it doesn't select them in the UI, it makes a list of them in the script, at which point you could walk through the list and operate on them, just as if you were running a script that required you to select your actions of interest before invoking it.

If what you wanted was a script that you could invoke by hand to create a selection of all the actions created in the last 2 seconds that you could then pass to another script or change in the inspector, you didn't make that sufficiently clear to me — I got the impression you were looking to do that in Applescript as part of a bigger script.

Replacing the "display alert" statement with "tell content of front window to select newTasks" should do what you want, I think.
 
Quote:
Originally Posted by whpalmer4 View Post
No, it doesn't select them in the UI, it makes a list of them in the script, at which point you could walk through the list and operate on them, just as if you were running a script that required you to select your actions of interest before invoking it.
Oh, that makes sense.

Quote:
Originally Posted by whpalmer4 View Post
If what you wanted was a script that you could invoke by hand to create a selection of all the actions created in the last 2 seconds that you could then pass to another script or change in the inspector, you didn't make that sufficiently clear to me.
Sorry, what I didn't realize is that I couldn't tack two scripts together with a few modifications. Almost all of the scripts work on selections in the UI working down through actions (or trees). That's cool the script already had the actions it needed to act on from your script. Unfortunately I didn't know how to modify the next script enough to make it do that.

I'm trying to cobble together scripts, which is not very elegant I realize. So I now realize that, yes I would want to pass this on to another script (through selections in the UI) for sheer lack of being able to make enough sense of the next script to implement it in more elegently :(.


Quote:
Originally Posted by whpalmer4 View Post
— I got the impression you were looking to do that in Applescript as part of a bigger script.

Replacing the "display alert" statement with "tell content of front window to select newTasks" should do what you want, I think.
Yes you are correct. I tried this as an experiment by putting in your code from another script you wrote. I modified it so it didn't work on selections, but it didn't work on even something simple! I am just lost on how to implement it in the script I am actually trying to use (see code 2, --Script 4, in this post below).

Code:
property pMaxAge : 2000 -- max number of seconds since creation for tasks of interest
property prependText : "[Action Created in the last 2000 seconds test] "

tell application "OmniFocus"
	set timeNow to current date
	set timeThen to timeNow - pMaxAge
	tell front document
		set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
			and repetition is missing value))
		
		
		--http://forums.omnigroup.com/showthread.php?p=101754#post101754
		
		
		tell front document
			
			set name of newTasks to prependText & name of newTasks
			
			
		end tell
	end tell
	
end tell
Anyway here is the AppleScript I am trying to make happen. I put *** on all the comments that might be helpful along the way.

Code:
--*** This script uses four scripts combined


--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.

---Script 1
tell application "OmniFocus"
	activate
	tell default document
		set FrontWindow to first document window whose index is 1
		tell FrontWindow
			
			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
			
			
			repeat with anItem in theItems
				if (class of anItem) is list then
					repeat with subItem in anItem
						if (class of subItem is 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
							
						end if
					end repeat
					
				else if (class of anItem is 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
					
				end if
			end repeat
		end tell
	end tell
end tell


--***Prepend text to select actions, which in this case would be the ones just marked as compleat but let's me know it is still "In Progress"
--http://forums.omnigroup.com/showthread.php?p=101754#post101754

--Script 2
property prependText : "[In Progress] "

tell application "OmniFocus"
	tell front document
		tell document window 1
			set oTrees to selected trees of content
			set IngTrees to count of oTrees
			if (IngTrees > 0) then
				set strPrepend to prependText
				
				repeat with iTree from 1 to IngTrees
					set oTask to value of (item iTree of oTrees)
					set name of oTask to strPrepend & name of oTask
				end repeat
			else
				display alert "No content selected!"
			end if
		end tell
	end tell
end tell


-- Bill's code from post 2 http://forums.omnigroup.com/showthread.php?p=101909#post101909

--Script 3
property pMaxAge : 2 -- max number of seconds since creation for tasks of interest
tell application "OmniFocus"
	set timeNow to current date
	set timeThen to timeNow - pMaxAge
	tell front document
		set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
			and repetition is missing value))
	end tell
	
	--***newTasks code should have gone here. Is there a way to tell it to "set" newTask to the following script?
	
end tell


--End of Bill's code from post 2 



-- ***Now change only the start date from absolute date (today's date) and not relitive 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.

--Script 4
(*
	# DESCRIPTION #
	
	This script "snoozes" the currently selected actions or projects by setting the start date to given number of days in the future.
	
	
	# LICENSE #
	
	Copyright © 2010 Dan Byler (contact: dbyler@gmail.com)
	Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
	
	
	# CHANGE HISTORY #
	
	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)

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

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


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)
				return
			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"
		try
			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
		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

Last edited by skillet; 2011-09-17 at 03:25 AM..
 
Quote:
Originally Posted by skillet View Post
I tried this as an experiment by putting in your code from another script you wrote. I modified it so it didn't work on selections, but it didn't work on even something simple!
OK, the problem with your first script here is that you aren't paying sufficient attention to the shapes and sizes of the pieces. newTasks is a list of tasks. The statement where you change the name to put on your string at the beginning is one that works on a single task — that's why the original script iterates through the list of tasks in the selection.

Code:
property pMaxAge : 2000 -- max number of seconds since creation for tasks of interest
property prependText : "[Action Created in the last 2000 seconds test] "

tell application "OmniFocus"
	set timeNow to current date
	set timeThen to timeNow - pMaxAge
	tell front document
		set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
			and repetition is missing value))
		
		
		--http://forums.omnigroup.com/showthread.php?p=101754#post101754
		
		
		tell front document
			repeat with myTask in newTasks
				set name of myTask to prependText & name of myTask
			end repeat
			
		end tell
	end tell
	
end tell
The "repeat with myTask in newTasks ... end repeat" construct I added causes the local variable myTask to be filled in turn with each successive entry in the list newTasks. Your second "tell front document ... end tell" is superfluous in this case, as you are still inside the scope of the original, although it probably doesn't do any harm, either.

It makes more sense to collapse the actions done by the multiple scripts down into one pass through the loop. I've done so in the following script, and finished up the date adjustment for you.

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)
			set newStart to oldStart + (days * (daysBetween + snoozeLength + 1))
			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
 
Oh wow, I am so happy I am going to cry like a little girl! Thank you so much this script ROCKS!!! I will use it daily for [Follow-Up] and [In Progress]. It is so amazing that it works flawlessly with repeating actions too! Now there is not the constant battle I have been having to mark them off, forward them, and then take of the repeat one by one. I found myself weekly checking to see if things were still starting on the right day with repeating actions.

This script is one of my all time favorites! I hope many people discover it.

I changed only one thing
Code:
set newStart to oldStart + (days * (daysBetween + snoozeLength + 1))
to
Code:
set newStart to oldStart + (days * (daysBetween + snoozeLength))
Since it was forwarding 1 extra day from today; I am sure that was intentional though.

Thanks also for the clarification on the first script syntax.

Attached are images from left to right in order of what this script does. You can change the [In Progress] to whatever you want or comment it out for those new (like me).

Thanks again!!!
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2011-09-17 at 8.50.28 PM.png
Views:	243
Size:	98.6 KB
ID:	2026   Click image for larger version

Name:	Screen shot 2011-09-17 at 8.50.52 PM.png
Views:	230
Size:	19.7 KB
ID:	2027   Click image for larger version

Name:	Screen shot 2011-09-17 at 8.51.11 PM.png
Views:	229
Size:	157.0 KB
ID:	2028  
 
Quote:
Originally Posted by skillet View Post
I changed only one thing
Code:
set newStart to oldStart + (days * (daysBetween + snoozeLength + 1))
to
Code:
set newStart to oldStart + (days * (daysBetween + snoozeLength))
Since it was forwarding 1 extra day from today; I am sure that was intentional though.
One thing I just discovered is that if an item starts at in the morning it with the change it will work correctly (i.e. 1 will be one day later). Anything after 12PM behaves differently. It will keep it the same day if one is entered (which the comment of the reason for the +1 makes more sense now). If you have 12PM and you run the script twice you will see it will toggle between tomorrow and today if you leave the +1 off and it won't advance a day if you don't for actions starting before noon.

I will see if I can figure it out.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


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 02:22 AM.


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