Applescript error number -1728 when trying to specify a project name for a new task
I'm writing some applescript to create new tasks and assign them to projects.
I want the user to be able to select which project to assign the task to by selecting the project out of a list. The list appears and it returns a project name like I would expect it to, but it doesn't seem to be a valid project name. I'm getting an error similar to the following when I try to run my script error "OmniFocus got an error: Can’t get project \"Example Project\" of document id \"e4Z5K4sRLLL\"." number -1728 from project "Example Project" of document id "e4Z5K4sRLLL" This is the code I am trying [CODE]set oDoc to default document tell oDoc set projNames to (name of (flattened projects of oDoc where hidden of its folder is false and its status is active)) set selectedProject to choose from list projNames with prompt "Choose project from the list." without multiple selections allowed set strProject to first item of selectedProject set theProject to project strProject set assigned container of newTask to theProject end tell[/CODE] The problem could be related to the structure of my data. The project "Example Project" is not a project at root level of the Library. It is in a folder. I think "flattened projects" is the wrong way to get the list of projects for what I am trying to do. I think I might need something that returns the folder name as well, but I didn't see anything in the applescript library like that. I'm new to AppleScript and this forum, so any pointers toward examples or other documentation are also appreciated. |
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 [/CODE] |
PS, for assignments of projects to tasks, see:
[URL="http://forums.omnigroup.com/showthread.php?t=22916"]http://forums.omnigroup.com/showthread.php?t=22916[/URL] |
@RobTrew - thank you for your quick help. For the next iteration of my little project, I am going to try using your project name "quick find" script instead of choosing from a list.
|
All times are GMT -8. The time now is 08:08 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.