Running into problems adding a tag in Omnifocus 3 with an AppleScript

I’m an admissions counselor at a university and I receive an email everyday telling me to retrieve transcripts from a document delivery service if transcripts were sent the day before. I’ve had a mail rule AppleScript running for a while that creates an inbox task in OmniFocus for me and archives the email so I don’t have to deal with it every morning. I would really like to update my script to tag the task and file it away in a project so it doesn’t just live in my inbox until I get it completed (I have another script that marks the task as complete when the document hits my downloads folder, it’s so nifty, makes me happy every day when it happens… but I digress). I’m just having trouble getting the script to add a tag, I’m not sure why, and it may be a dumb mistake on my part. I just can’t figure out what I’m doing! Heres the script:

set my_date to (current date)
tell my_date
	set {its hours, its minutes, its seconds} to {13, 0, 0}
end tell
tell application "OmniFocus"
	activate
	tell default document
		set theTag to the first flattened tag where its name = "Today"
		set newTask to make new inbox task with properties {name:"Check for Royall Applications", due date:my_date, primary tag:theTag}
	end tell
end tell

I’ll attach a screenshot of the problem section in the script below with it’s error code…

Can anyone help me?! as much as I’m enjoying avoiding my actual job by trying to figure this out, I probably need to get back to work sooner than later :stuck_out_tongue_winking_eye:.

I swapped the code formatting to a block instead of a line - it makes it a little easier to read :wink:

So the properties you are looking for are

  • project - the project you want to create the task inside of
  • primary tag - which is the first tag of a task

Our very own @MacSparky has a script which can point you in the right direction for the project too: Create OmniFocus Tasks With AppleScript

The part that interests us is the following:

        set theProject to first flattened project where its name = "Finance"
        tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}

Your script is working for me with the tag - once I had created a Today tag anyway, so all we need to do is add the project.

set my_date to (current date)
tell my_date
	set {its hours, its minutes, its seconds} to {13, 0, 0}
end tell
tell application "OmniFocus"
	activate
	tell default document
		set theTag to the first flattened tag where its name = "Today"
		set theProject to first flattened project where its name = "Testing"
		tell theProject to make new task with properties {name:"Check for Royall Applications", due date:my_date, primary tag:theTag}
	end tell
end tell

That’s it! You just need to change the project to match what you want :slight_smile:

1 Like

Thanks a million!

I love the show by the way. :blush:

1 Like