The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Getting task ID into variable - help :( (http://forums.omnigroup.com/showthread.php?t=21749)

StefMercury 2011-07-28 11:54 AM

Getting task ID into variable - help :(
 
Hi, I am totally new to scripting - thus far all I want to be able to do is create a new task from Filemaker Pro into Omnifocus - I have a script that does this.

The snippet which makes the new tasks is below - obviously I substitute variables in place of the hard coded strings.

BUT, how do I get the ID of this newly created task so I can store it in a variable? I have tried set myTaskID to id of task as a command directly after the make new inbox task but this fails --- I have tried what seems like 100 other variations.

tell application "OmniFocus"
tell the first document
make new inbox task with properties {name:"test", note:"test 2", flagged:true}
end tell
end tell


Could anyone help an idiot?!

Thank you

P.S. I am also an idiot because I posted this to the wrong forum! Not sure how to delete this and start again!

StefMercury 2011-07-28 01:05 PM

Getting task ID into variable - help :(
 
Hi, I am totally new to scripting - thus far all I want to be able to do is create a new task from Filemaker Pro into Omnifocus - I have a script that does this.

The snippet which makes the new tasks is below - obviously I substitute variables in place of the hard coded strings.

BUT, how do I get the ID of this newly created task so I can store it in a variable? I have tried set myTaskID to id of task as a command directly after the make new inbox task but this fails --- I have tried what seems like 100 other variations.

tell application "OmniFocus"
tell the first document
make new inbox task with properties {name:"test", note:"test 2", flagged:true}
end tell
end tell


Could anyone help an idiot?!

Thank you

teobaldo 2011-07-28 11:36 PM

Catch the result of the 'make' command like so:[CODE]set newTask to make new inbox task with properties {name:"test", note:"test 2", flagged:true}[/CODE]
or[CODE]make new inbox task with properties {name:"test", note:"test 2", flagged:true}
set newTask to the result[/CODE]
In the second form you *must* get 'result' immediately after the command that generates that result, or it will be lost forever.

RobTrew 2011-07-28 11:40 PM

Either of these should work:

[CODE]tell application "OmniFocus"
tell front document
set oTask to (make new inbox task with properties {name:"test", note:"test 2", flagged:true})
set strID to id of oTask
end tell
end tell

-- OR
tell application "OmniFocus"
tell front document
tell (make new inbox task with properties {name:"test", note:"test 2", flagged:true})
set strID to id
end tell
end tell
end tell[/CODE]

RobTrew 2011-07-29 12:16 AM

Or even, (if [I]id[/I] is the only property that you need to get from the new task object that is returned by the [I]make[/I] command):

[CODE]tell application "OmniFocus"
tell front document
set strID to id of (make new inbox task with properties {name:"test", note:"test 2", flagged:true})

end tell
end tell[/CODE]

StefMercury 2011-07-29 06:42 AM

Thank you for that....so easy when you know how :)

StefMercury 2011-07-29 06:44 AM

Thank you!!!!

This has only driven me mad for 3 days. Thank you for your time in answering that one...greatly appreciated.

Brian 2011-07-29 02:26 PM

Glad this got sorted out, but please don't post items in multiple threads to try and up the chances of getting a response - it makes the forums less useful for other guests.

If you need a guaranteed response, it's better to post to the forums and then email the [EMAIL="omnifocus@omnigroup.com"]support ninjas[/EMAIL] about the thread. Thanks!

(Merging threads.)

StefMercury 2011-07-29 02:40 PM

Sorry Brian - I did put in the other post I had posted to the wrong forum and didn't know how to delete! Regards.


All times are GMT -8. The time now is 02:17 PM.

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