The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Scripting: Using a selected range of tasks (http://forums.omnigroup.com/showthread.php?t=14692)

aleding 2009-12-01 02:18 PM

Scripting: Using a selected range of tasks
 
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
[/CODE]

webalstrom 2009-12-02 08:14 AM

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)[/CODE]

to

[CODE] set dateTarget to (8/8/88)[/CODE]

(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

whpalmer4 2009-12-02 09:21 AM

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 :)

webalstrom 2009-12-02 11:19 AM

whpalmer4,

That worked like a charm. Thanks for your help!

Eric

aleding 2009-12-02 03:13 PM

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[/CODE]

aleding 2009-12-02 03:15 PM

[QUOTE=webalstrom;70405]whpalmer4,

That worked like a charm. Thanks for your help!

Eric[/QUOTE]

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[/CODE]

RobTrew 2009-12-06 09:01 PM

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"

[B]set lstTree to selected tree of content of front window[/B]
set dteTarget to current date

if length of lstTree > 0 then

[B]repeat with oItem in lstTree
set oTask to value of oItem
set start date of oTask to dteTarget
end repeat[/B]

end if

end tell
[/CODE]
[COLOR="White"]--[/COLOR]


All times are GMT -8. The time now is 10:26 PM.

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