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 > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Applescript to Create Repeating Tasks Thread Tools Search this Thread Display Modes
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
Any help will be appreciated.
 
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
 
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}
to

Code:
set _repetition to {unit:year, steps:1, fixed:true}
--
 
Rob, you had the secret to eternal life right there in front of you, and you missed it! :-)
 
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 ...
 
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 date 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 display dialog, 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
--

Last edited by RobTrew; 2011-02-08 at 05:07 PM.. Reason: Added text of birthday to action string
 
Rob is awesome. That is all. :-)
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript: How to create a group or subgraph? Sophie OmniGraffle General 2 2012-11-27 02:19 AM
repeating projects/tasks when all tasks/subtasks are complete? djc225 OmniFocus 1 for Mac 1 2012-03-20 07:55 PM
omniplan applescript create milestones xtream OmniPlan Extras 1 2011-10-17 10:24 AM
Create Repeating Tasks LG2008 OmniFocus for iPhone 1 2008-07-21 08:28 PM
MailAction.applescript doesn't create anything in OF Dalmet OmniFocus 1 for Mac 8 2007-11-18 11:19 AM


All times are GMT -8. The time now is 10:40 AM.


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