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 > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
AppleScript question Thread Tools Search this Thread Display Modes
I'm using Mail rules to turn reports generated by Netsuite into to-dos. Works great - they go into my inbox.

I would like to take this to the next level, and use AppleScript to automatically assign the items that come in to a specific project, context, and set due date to today.

I've tried to find a pre-written AppleScript but have come up dry. Any tips on how to do this? Or where to go to find an AppleScript I can modify for this purpose?

I would be fine with it either happening automatically, when the tasks come into OmniFocus - or manually - I select the tasks and run the script so they all "leave" the inbox and get filed.

Thanks, Dave
 
Dave,

Have you look at the OF Extras forum? That's the home for Applescripting OmniFocus. You'll find links to a bunch of scripts there. My Complete and Await Reply script (available from my software page) does some of what you're looking for. It mucks with contexts and dates, so it might serve as a starting point.

It will be easier if you just process the tasks in place, then use the Clean Up command to get them out of the inbox. Clean Up can be called from a script.
__________________
Cheers,

Curt
 
I tried this:

tell application "OmniFocus"
tell front document
-- Gets target context
tell content of document window 1 -- (first document window whose index is 1)
set theSelectedItems to value of every selected tree
if ((count of theSelectedItems) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
repeat with anItem in theSelectedItems
set the project of anItem to "AP, AR, Finance"
set name of the context to "Online"
set due date of the task to "today"
end repeat
end tell
end tell
end tell

I just want to set the context, project, and due date of selected items to: "Online", "AP, AR, Finance", and "Today" respectively. I tried a couple of different ways in the script above, but they both failed.

I'm sure this can't be that hard, but my AppleScript skills are missing.

Thanks,

Dave
 
I've updated your AppleScript below. I had to capture the context by using the line:

set theContext to the context "Online"

This gets the context's ID and passes it to the selected items in the script.

Next I changed due date from "today" to "current date", AppleScript's term for getting today.

I've also added a test to see if the selected item is a project by trapping for a parent task. I don't know if that's the correct way to test an item for being a project but it's all I could come up with for now.

Anyway, it works fine in my OmniFocus, you may want to do some testing with various projects to make sure.


tell application "OmniFocus"
tell front document
set theContext to the context "Online"

-- Gets target context
tell content of document window 1 -- (first document window whose index is 1)
set theSelectedItems to value of every selected tree
if ((count of theSelectedItems) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
repeat with anItem in theSelectedItems
if parent task of anItem = missing value then
set name of anItem to "AP, AR, Finance"
set context of anItem to theContext
-- set properties of anItem to {context:ActionContext}
else
set context of anItem to theContext
set due date of anItem to current date
end if
end repeat
end tell
end tell
end tell
 
Quote:
Originally Posted by DamonC View Post
I've also added a test to see if the selected item is a project by trapping for a parent task. I don't know if that's the correct way to test an item for being a project but it's all I could come up with for now.
To check whether anItem is a project use:
Code:
if (class of anItem is project) then
    -- do something projecty with anItem
end if
__________________
Cheers,

Curt
 
Thanks Curt, I haven't had the time to play with the dictionary for OmniFocus yet.

In this case, the script should be as follows:

tell application "OmniFocus"
tell front document
set theContext to the context "Mac"

-- Gets target context
tell content of document window 1 -- (first document window whose index is 1)
set theSelectedItems to value of every selected tree
if ((count of theSelectedItems) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
repeat with anItem in theSelectedItems
if (class of anItem is project) then
set name of anItem to "AP, AR, Finance"
else
set due date of anItem to current date
end if
set context of anItem to theContext
end repeat
end tell
end tell
end tell
 
THanks for your help!

Quote:
Originally Posted by DamonC View Post
I've updated your AppleScript below. I had to

tell application "OmniFocus"
tell front document
set theContext to the context "Online"

end tell
When I run the script sample you kindly provided, I get the error:

Quote:
OmniFocus got an error: Canít get context "Online" of document 1.
I know I have a context "Online" in that document. More specifically, it is "Mac : Online". I tried that too, but get the same error.

Something I'm doing wrong?

Thank you,

Dave
 
Hi Dave,

Your original post stated that you wanted the context to be set to "Online" which is what I put in the script. What you're now saying is that Online is actually a sub-context of Mac, is that right? I also confused the issue by changing the context to "Mac" in the last script I sent as well.

If Online is a sub-context of Mac, just change the third line of the script to:

set theContext to context "Online" of context "Mac"
 
DamonC,

Thanks. AppleScript has a kind of biblical cant, doen't it? Just lots of "ofs" instead of "begats"...

I'm tripping up now on setting the project. I tried a couple of different things, and didn't get anything to work. Here's the latest script. (I know that the selected item has no parent task, so I don't need to test for it with this script.) The error is:

Quote:
OmniFocus got an error: Can’t set name of missing value to "AP, AR, Finance".
tell application "OmniFocus"
tell front document
set theContext to the context "Online" of context "Mac"
tell content of document window 1 -- (first document window whose index is 1)
set theSelectedItems to value of every selected tree
if ((count of theSelectedItems) < 1) then
display alert "You must first select an item to complete." as warning
return
end if
repeat with anItem in theSelectedItems
set name of parent task of anItem to "AP, AR, Finance"
set context of anItem to theContext
set due date of anItem to current date
end repeat
end tell
end tell
end tell

In this case, "AP, AR, Finance" is in the folder "Operations & Finance" which is in the folder "Work" in "Library".

I tried "AP, AR, Finance" of parent task "Operations & Finance" of parent task "Work"... but I get this error:

Quote:
Expected end of line but found “"”
I'm sorry to be so dense. I'm told that AppleScript is great because it's just like English, only I don't speak that way!

Best,

Dave
 
A problem with what you have there is that you're trying to set the name of the parent task of an item in the Inbox, and there is no parent task (because it is in the Inbox), and you can't set the name of a non-existent task...

If you ran the script as written on a task that was not a top-level task (in other words, was a task inside a project in the library), you would rename the action group or project that contained the task, but not assign the task to the desired destination.

I believe you need to actually find the destination project by iterating through all of the contents of the library looking for a matching name, then set the parent task of the task in the Inbox to be that destination project, then do a clean up (compact). Regretfully, I can't think of a good example to copy...
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Email/iOS/Mailtags Question... more GTD question more than OmniFocus filmgeek Applying OmniFocus 3 2010-11-06 06:00 AM
Applescript question for Omni Group pvonk OmniFocus 1 for Mac 3 2009-10-06 09:16 AM
Dead stoopid AppleScript question: finding the tell target jporten OmniFocus Extras 1 2009-03-19 10:10 AM
Omniweb Applescript Question russophile OmniWeb General 4 2008-03-14 12:56 PM


All times are GMT -8. The time now is 08:44 PM.


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