The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Can't send emails to specific project in OF (http://forums.omnigroup.com/showthread.php?t=25011)

ofuser 2012-07-26 02:39 PM

Can't send emails to specific project in OF
 
I've copied the following script and adapted it a bit. (I'm not sure where I copied it from since I've either deleted it or there was no contact information in the script.)

It was working fine before upgrading to Mountain Lion but now instead of creating a task in the folder "Waiting For..." with the context "Waiting For..." it creates a task in the Inbox. The task does have the correct start date (current date + 2 days).

Any help would be great.

Thanks


on run

tell application "Mail"


set _msgs_to_capture to selection

repeat with eachMessage in _msgs_to_capture
set theStart to (current date) + (2 * days)
set theDue to missing value
set theOmniTask to missing value

set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theContextName to "Waiting For..."
set theProjectName to "Waiting For..."

set theCombinedBody to "message://%3c" & message id of eachMessage & "%3e" & return & return & theNotes

tell application "OmniFocus"
tell default document
set newTaskProps to {name:theTitle}
set theContext to context theContextName
set theProject to project theProjectName
set newTaskProps to newTaskProps & {containing project:theProject}
set newTaskProps to newTaskProps & {context:theContext}
if theStart is not missing value then set newTaskProps to newTaskProps & {start date:theStart}
if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}

tell theProject
set newTask to make new task with properties newTaskProps
end tell

end tell
end tell


end repeat

end tell

end run

Lizard 2012-07-26 05:00 PM

My AppleScript's a little fuzzy, so I'm not seeing the problem right away.
However, here's what I would do to debug it:

Add this line:
[CODE]display dialog name of theProject as string[/CODE]

Right before:
[CODE]tell theProject[/CODE]

This will let you know if you've actually found the project you mean to find or not.

Staring harder, maybe change
[CODE]set theProject to project theProjectName[/CODE]
to
[CODE]
set theProject to project named theProjectName[/CODE]

ofuser 2012-08-08 06:50 AM

I've made the two suggested changes:

[CODE]set theProject to project named theProjectName[/CODE]
[CODE]display dialog name of theProject as string[/CODE]

I added the following line after "tell theProject"

[CODE]set theProject to project named theProjectName[/CODE]

I get the following error:
OmniFocus got an error: Can’t get project "Waiting For..." of project id "f3xRiry3AmI" of document id "dmjA-CUMhkW".

It appears it can't find the project but the project "Waiting For.." exists in OmniFocus and is active and not nested.

Thanks

RobTrew 2012-08-08 10:08 AM

One approach to a GetProject function might look like this:

[CODE]tell application id "OFOC"
set oDoc to default document
set oProj to my GetProject(oDoc, "Integrate top-level themes")
end tell

on GetProject(oDoc, strName)
using terms from application "OmniFocus"
tell oDoc
set lstProj to flattened projects where name begins with strName
if length of lstProj < 1 then return missing value
return item 1 of lstProj
end tell
end using terms from
end GetProject[/CODE]


All times are GMT -8. The time now is 06:26 PM.

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