Guest
2011-12-28, 12:32 AM
Yes, you can identify top level projects by their name, but for nested projects you need their id.
I usually do something like this:
Code:
property projIDs : {}
property projNames : {}
tell application id "OFOC"
set oDoc to default document
tell oDoc
-- RETRIEVE IDs AS WELL AS NAMES
set {projIDs, projNames} to {id, name} of (flattened projects of oDoc where hidden of its folder is false and its status is active)
-- HOW MANY DIGITS WILL WE NEED FOR A NUMERIC INDEX TO THE LAST PROJECT ?
set lngProj to length of projIDs
set lngDigits to (length of (lngProj as string))
-- PREFIX PROJECT NAMES WITH NUMERIC INDICES
repeat with i from 1 to lngProj
set item i of projNames to my PadNum(i, lngDigits) & " " & item i of projNames
end repeat
-- GET THE USER'S CHOICE AS A NUMERIC INDEX, RATHER THAN AS A NAME
set selectedProject to choose from list projNames with prompt "Choose project from the list." without multiple selections allowed
if selectedProject is not false then
set {dlm, my text item delimiters} to {my text item delimiters, " "}
set lngIndex to (first text item of item 1 of selectedProject) as integer
set my text item delimiters to dlm
end if
-- RETRIEVE THE ID FROM THE INDEXED POSITION IN THE ID LIST
set lngID to item lngIndex of projIDs
-- IDENTIFY THE PROJECT BY ITS ID
set theProject to project id lngID
end tell
end tell
on PadNum(lngNum, lngDigits)
set strNum to lngNum as string
set lngGap to (lngDigits - (length of strNum))
repeat while lngGap > 0
set strNum to "0" & strNum
set lngGap to lngGap - 1
end repeat
strNum
end PadNum
Last edited by RobTrew; 2011-12-28 at 12:43 AM..
Reason: typo in code comment