The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniPlan Extras (http://forums.omnigroup.com/forumdisplay.php?f=45)
-   -   what is the fastest way to search tasks based on custom data in AppleScript (http://forums.omnigroup.com/showthread.php?t=13005)

cope360 2009-07-10 11:54 AM

what is the fastest way to search tasks based on custom data in AppleScript
 
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]

Lizard 2009-07-16 10:15 AM

[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
[/CODE]

cope360 2009-07-16 02:57 PM

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
[/CODE]


All times are GMT -8. The time now is 05:00 AM.

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