New Apple Script and Perspectives in Omnifocus

The challenge of coding, is that you sometimes need to be aware of what can be impacted outside of your code to make it appear guilty.


I wrote a blog post a short time back on my first time scripting with Apple Script with a goal of automating my weekly status reports to my new manager of my tasks in OmniFocus.  After seeing some cool stuff one of my peers did with their setup in OmniFocus, I built out mine to do something similar.  What I didn’t realize, was that my code was significantly dependent on my original setup and no new updates were created post the change.

Now that I know a little bit more about Apple Scripting and Omni Focus, I chose to do the following:

  1. Use Omnifocus’ Perspectives to give me a better status report output.
  2. Simplify my code to use the perspective vs. me “scraping” the data in Omnifocus.

For the database folks out there, a Perspective is just like a view in a database.  It’s just an alias with a selection of data that answers the query, “What have I completed in the last month, listing the project, the notes on my status and organize it by date completed.”

Create Perspective

You can create a new Perspective quite easily:


You can create the perspective, (I’ve named mine “Weekly Report” and then create the “view” that will populate our report properly.


Apple Script

Now, we’ll need to build our code to match what our perspective is done:

--Set up code to match the perspective

set thePerspective to "Weekly Report" --The exact Perspective name
set theSubjectOfMessage to "Task Report for Kellyn" --The Subject of Email
set theSender to "Kellyn Gorman"
set POSIXpath to POSIX path of "/Users/pathname/Library/Containers/com.omnigroup.OmniFocus2/Data/Documents/tasklist.txt"
tell front document of application "OmniFocus"
 tell front document window
 set perspective name to thePerspective
save in POSIXpath as "public.text"
 end tell
end tell
tell application "Mail"
 set theMessage to make new outgoing message with properties {subject:theSubjectOfMessage, sender:theSender}
 tell content of theMessage
make new attachment with properties {file name:POSIXpath} at after last paragraph
 end tell
 tell theMessage
make new to recipient at end of to recipients with properties {address:""} --add address for email
 end tell
send theMessage
end tell

And test your code…always… 🙂  If you’ve set everything up correctly, then you should have an awesome weekly status report sent to your manager telling him how awesome you are.

Print Friendly
November 23rd, 2016 by

facebook comments:

  • Facebook
  • Google+
  • LinkedIn
  • Twitter