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

 
what is the fastest way to search tasks based on custom data in AppleScript Thread Tools Search this Thread Display Modes
For some of my tasks I have a custom data field "tracid" set. In AppleScript I need to find the task where the tracid is set to a particular value.

Currently I am just iterating over the list of tasks until I find the one I want. Is there any faster way to do this?

Code:
-- Finds a Task
--   _id : tracid of task
on findTask(_id)
	tell application "OmniPlan"
		tell first document
			
			repeat with t in tasks
				set customData to get custom data of t
				if customData is not {} then
					if (tracid of customData = _id) then
						return t
					end if
				end if
			end repeat
			
			return false
			
		end tell
	end tell
end findTask
 
Code:
-- Finds a Task
--   _id : tracid of task
on findTask(_id)
	tell application "OmniPlan"
		tell first document
			set t to first task whose value of custom data entry "tracid" is _id
			if exists t then
				return t
			else
				return false
			end if
		end tell
	end tell
end findTask
 
Thanks for the help Lizard.

I tried your code and it causes an error when the task is not found instead of returning false.

I think this is the ticket:
Code:
-- Finds a Task
--   _id : tracid of task
on findTask(_id)
	tell application "OmniPlan"
		tell first document
			try
				set t to first task whose value of custom data entry "tracid" is _id
			on error errmesg number errn
				if errn is -1719 then
					return false
				else
					error errmesg number errn
				end if
			end try
			return t
		end tell
	end tell
end findTask
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can custom data be printed jethiele OmniPlan General 5 2012-04-20 10:27 AM
Custom text exports from OmniFocus (applescript-based query language) RobTrew OmniFocus Extras 0 2011-01-14 06:08 AM
Searching custom data edwagner OmniPlan General 1 2010-09-17 09:19 PM
OmniOutliner: Fastest way to set data in rows, columns or blocks? nelsonm AppleScripting Omni Apps 3 2009-07-27 02:45 PM
Setting Task Custom Data using Applescript jubo OmniPlan General 6 2007-08-22 10:05 AM


All times are GMT -8. The time now is 12:52 PM.


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