View Single Post
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
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.