The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Applescript to Create Repeating Tasks (http://forums.omnigroup.com/showthread.php?t=20043)

AgentsSka 2011-02-07 03:38 PM

Applescript to Create Repeating Tasks
 
I'd like to create an applescript that creates a repeating task in a specified project. For example, I want to set up a repeating annual task for me to acknowledge Birthdays. I'm having a problem defining the properties.

[CODE]tell application "OmniFocus" to tell default document
make new task with properties {name:"Birthday Test", containing project:
"Birthdays", start date:2/12/2011, due date:2/16/2011, context:"Mac:Email",
repetition:"1 year"}
end tell[/CODE]

Any help will be appreciated.

Brian 2011-02-07 04:54 PM

Don't feel bad about needing help - OmniFocus' library is a little tricky to work with. (I can script Outliner just fine, but I had to ask an engineer for help with this.)

Something along these lines should work. You want to find the project, then tell it to add actions to itself. (Containing Project is read-only.)

Also, changed the date entry - the way they were before was actually a mathematical expression.

[CODE]
tell application "OmniFocus"
tell default document
set _context to context "Email" of context "Mac"
tell project "Birthdays"
set _startDate to date "Saturday, February 12, 2011 12:00:00 AM"
set _dueDate to date "Wednesday, February 16, 2011 12:00:00 AM"
set _repetition to {unit:year, steps:1}
make new task with properties {name:"Birthday Test", start date:_startDate, due date:_dueDate, repetition:_repetition, context:_context}
end tell
end tell
end tell
[/CODE]

RobTrew 2011-02-08 08:57 AM

My only comment on this helpful piece of code is that it implements an ethnographically unfamiliar version of birthdays ...

It creates an action that repeats a year after "completion" of the action, rather than every year on the same day. If I forget your birthday and email you two days later, then your next birthday will fall two days later than the day which your mother remembers ...

For the more traditional kind of birthday, you can edit the line:

[CODE]set _repetition to {unit:year, steps:1}[/CODE]

to

[CODE]set _repetition to {unit:year, steps:1, fixed:true}[/CODE]

[COLOR="White"]--[/COLOR]

whpalmer4 2011-02-08 09:18 AM

Rob, you had the secret to eternal life right there in front of you, and you missed it! :-)

RobTrew 2011-02-08 09:32 AM

You're right :-)

And it's a pity, because I'm already too old to digest all this post-modern relativism and social constructivism ...

In my day time was a property of nature, but now it seems we only age because others remember our birthdays ...

RobTrew 2011-02-08 12:40 PM

PS

AgentSka appears to be in north america, where Brian's code will compile and run first time.

Anyone using a system with different regional settings may, however, find that Applescript chokes on the [I]date[/I] expressions, complaining that it is unable to parse their date format.

One way of writing code that can be run outside the Month/Day/Year zone is to use [I]display dialog[/I], and ask it to prompt users with a date in the format which their applescript installation will understand.

e.g. something like

[CODE]property pTitle : "Enter a repeating birthday reminder"
property plngDaysNotice : 3

set strName to (text returned of (display dialog "Whose birthday:" default answer "" with title pTitle))
try
set dteDue to date (text returned of (display dialog strName & "'s birthday falls on:" default answer short date string of (current date) with title pTitle))
on error strMsg
display dialog strMsg buttons {"OK"} with title pTitle
return
end try
set dteStart to ((dteDue) - (plngDaysNotice * days))

tell dteDue
set strMonth to its month as string
set strDay to its day as string
end tell

tell application "OmniFocus"
tell default document
set _context to context "Email" of context "Mac"
tell project "Birthdays"
set _repetition to {unit:year, steps:1, fixed:true}
make new task with properties {name:strName & "'s birthday on " & strMonth & space & strDay, start date:dteStart, due date:dteDue, repetition:_repetition, context:_context}
end tell
end tell
end tell[/CODE]

[COLOR="White"]--[/COLOR]

Brian 2011-02-08 03:00 PM

Rob is awesome. That is all. :-)


All times are GMT -8. The time now is 09:05 AM.

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