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

 
AppleScript: adding a task Thread Tools Search this Thread Display Modes
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
 
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
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
So I'm secretly hoping you won't ask. The above definitely won't work.

-Tom
 
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
 
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.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding an attachment to a task created with AppleScript via Hazel HirnHorn AppleScripting Omni Apps 0 2013-03-05 11:54 PM
Applescript for adding some text when I drag circle ashokmatoria OmniGraffle Extras 1 2011-05-19 02:49 AM
Adding resources makes task take longer? jim lee OmniPlan General 1 2008-12-04 01:12 PM
Tip and Feature Request for iPhone Email Task Adding jicksta OmniFocus 1 for Mac 1 2008-04-17 10:25 AM
HELP:Adding a task (in OF's latest build) rish OmniFocus 1 for Mac 1 2007-06-04 03:32 PM


All times are GMT -8. The time now is 04:51 AM.


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