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

 
Scripting: Using a selected range of tasks Thread Tools Search this Thread Display Modes
Fellow OmniFocus users,

I have been trynig to get an AppleScript of mine to work on a selected range of tasks and was able to figure this out yesterday. Therefore, I thought I would share what I did to both share but also to see if anyone else might have a better solution. The script below sets the Start Date of the selected tasks to the current date + 21 days.

Let me know your thoughts - Thanks.

Code:
tell application "OmniFocus"
	tell application "Finder"
		set dateTarget to (current date)
		set day of dateTarget to ((day of dateTarget) + 21)
	end tell
	set taskList to count of the items of the selected tree of the content of document window 1 of document 1
	set taskPtr to 1
	repeat taskList times
		set taskTmp to the value of item taskPtr of the selected tree of the content of document window 1 of document 1
		set start date of taskTmp to dateTarget
		set taskPtr to (taskPtr + 1)
	end repeat
end tell
 
That works great, although I changed it to add just 1 day to the start date. I might make a 7 day version too!

I would also find it useful to set an exact date, too. To put tasks (especially single actions) on hold, I put a start date of 8/8/88. This is so far in the future that I won't have to worry about them becoming active by mistake and the sequence is very distinctive so I know at a glance the task is on hold.

I have tried to change the following lines:

Code:
                set dateTarget to (current date)
                set day of dateTarget to ((day of dateTarget) + 21)
to

Code:
                set dateTarget to (8/8/88)
(eliminating the second line)

but the date format I am trying doesn't work. I've tried many variations on this (with quotes, in mm/dd/yyyy and yyyymmdd formats, etc) to no avail.

What is the correct format for inputting direct dates and is it even possible?

Thanks,
Eric
 
You could use

set dateTarget to date "8/8/88" (which will be expanded when compiled)

If I use a date after Feb 5, 2040 I get an error when it tries to convert it to a string. You can certainly set a later due date through the UI, so I'm not quite sure why this gives Applescript heartburn. An exercise left for the reader, as they say in the textbook biz :)
 
whpalmer4,

That worked like a charm. Thanks for your help!

Eric
 
First off, glad you guys like the code - next as to the specifc date idea, this is exactly what I did but I used 12/31/99 but the result is the same.

Next, I thought I would post another one I wrote that allows you to push out a range of tasks by one month without affecting the day. This probably seems intuitive but the code is a little different because you want to preserve the day value. Also, this can be easily modified to whichever value you wish - for example 3 months rather than just one.

Lastly, in case you are wondering why I am asking Finder to make the date calculations - this is due to an existing OmniFocus bug where the app will not allow proper date calculations. I have a bug report open with Omni so hopefully they can get it fixed soon but even so, this little workaround seems to be fine.

Enjoy...

Code:
tell application "OmniFocus"
	set taskList to count of the items of the selected tree of the content of document window 1 of document 1
	set taskPtr to 1
	repeat taskList times
		set taskTmp to the value of item taskPtr of the selected tree of the content of document window 1 of document 1
		set dateTarget to start date of taskTmp
		tell application "Finder"
			set month of dateTarget to ((month of dateTarget) + 1)
		end tell
		set start date of taskTmp to dateTarget
		set taskPtr to (taskPtr + 1)
	end repeat
end tell
 
Quote:
Originally Posted by webalstrom View Post
whpalmer4,

That worked like a charm. Thanks for your help!

Eric
Yeah - I think the issue you had was the missing quotes - I am able to use the 12/31/99 date with no issues - see my version here:

Code:
tell application "OmniFocus"
	set dateTarget to date ("12/31/2099")
	set taskList to count of the items of the selected tree of the content of document window 1 of document 1
	set taskPtr to 1
	repeat taskList times
		set taskTmp to the value of item taskPtr of the selected tree of the content of document window 1 of document 1
		set start date of taskTmp to dateTarget
		set taskPtr to (taskPtr + 1)
	end repeat
end tell
 
Not of much consequence with only a few items selected, but it is generally a good idea to cache references, and avoid repeatedly fetching the same data across object interfaces.

i.e. you can save a little ink and run-time with something like:

Code:
tell application id "com.omnigroup.OmniFocus"
	
	set lstTree to selected tree of content of front window
	set dteTarget to current date
	
	if length of lstTree > 0 then
		
		repeat with oItem in lstTree
			set oTask to value of oItem
			set start date of oTask to dteTarget
		end repeat
		
	end if
	
end tell
--

Last edited by RobTrew; 2009-12-07 at 07:25 AM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting bridge: crash when trying to get child tasks of a task amorya OmniFocus Extras 8 2013-11-10 05:00 AM
Selected Tasks to iCal uku OmniFocus Extras 29 2009-09-22 09:35 AM
Reporting or Listing Tasks by a Date Range? Ciscok1d OmniFocus 1 for Mac 3 2008-10-23 10:07 AM
Get selected tasks with script? curt.clifton OmniFocus 1 for Mac 1 2007-06-10 05:43 PM


All times are GMT -8. The time now is 07:47 AM.


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