The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniPlan General (http://forums.omnigroup.com/forumdisplay.php?f=37)
-   -   AppleScript: adding a task (http://forums.omnigroup.com/showthread.php?t=2771)

dontlament 2007-02-06 07:16 PM

AppleScript: adding a task
 
Hi Everyone,

Good to see the developers of the app involved here. I'm sure everyone appreciates their help.

I am having some issues. I've never done much ActionScript but I have most of it working but the OmniPlan part is a bit differernt.

I'm trying to open an existing OmniPlan document and add a new task to the document. I don't seem to be able to add a task.

The code I have atm is:

[CODE]tell application "OmniPlan"
activate "OmniPlan"

set myDoc to make new document

tell myDoc
--set myDoc to front document

tell front document
set Myself to make new resource with properties {kind:person, efficiency:2, name:"Tom", cost per hour:200.0}
set MyTask to make new task with properties {name:"Cure Cancer", duration:8.0}
assign MyTask to Myself
end tell
end tell

end tell[/CODE]

Tom Bunch 2007-02-06 10:15 PM

It looks like you're mostly having trouble getting a document reference - the innermost code you have looks fine (though eventually I'm sure you'll want to see if your resource (me!) already exists in your document).

You say the document already exists? Let's say for the moment that you know it's already populated with resources. Try something like this:

[CODE]tell application "OmniPlan"

open "::Users:tom:foo.omniplan"
set myDoc to document "foo"
tell myDoc
set Myself to first resource whose name is "Tom"
set MyTask to make new task with properties {name:"Cure Cancer", duration:8.0}
assign MyTask to Myself
end tell

end tell
[/CODE]

Honestly, I'm not sure how to write something like

[CODE]if Myself is null then
set Myself to make new resource with properties {kind:person, efficiency:2, name:"Tom", cost per hour:200.0}
end if[/CODE]

So I'm secretly hoping you won't ask. The above definitely won't work.

-Tom

Tom Bunch 2007-02-07 10:30 AM

Ok, it bothered me that I couldn't figure out the "find or create resource" code so I got Lizard to help me out.

[CODE]tell application "OmniPlan"

-- This probably doesn't work in 1.1 beta 1 and earlier releases
set myDoc to open "Users:tom:Desktop:PlanTest:foo.omniplan"
-- The following, commented out code is the workaround
-- open "Volumes:Extra:Users:tom:Desktop:PlanTest:foo.omniplan"
-- set myDoc to document "foo.omniplan"

tell myDoc
set myToms to resources whose name is "Tom"
if (count of myToms) > 0 then
set Myself to first item of myToms
else
set Myself to make new resource with properties {kind:person, efficiency:2, name:"Tom", cost per hour:200.0}
end if

set MyTask to make new task with properties {name:"Cure Cancer", duration:8.0}
assign MyTask to Myself
end tell

end tell
[/CODE]

dontlament 2007-02-07 02:15 PM

Thanks so much Tom! This worked a treat, and I was able to extend it to create child tasks based on a filename structure coming through from finder. Just presented it to my bosses and they were damn impressed as they think it will save them a lot of time.


All times are GMT -8. The time now is 10:12 AM.

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