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

 
Applescript error number -1728 when trying to specify a project name for a new task Thread Tools Search this Thread Display Modes
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.
 
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 01:43 AM.. Reason: typo in code comment
 
PS, for assignments of projects to tasks, see:

http://forums.omnigroup.com/showthread.php?t=22916
 
@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.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript to change the Project of a task? Kha OmniFocus Extras 2 2011-12-19 03:10 PM
Add quick entry task with project using AppleScript iNik OmniFocus Extras 2 2011-08-30 01:40 PM
Error when syncing to WebDAV if there's a port number specified gmichaud Other WebDAV 12 2008-09-03 10:13 AM
AppleScript help: Create sub-task, project from task iNik OmniFocus Extras 3 2007-12-05 09:53 AM
Extract the Legal para number using Applescript Simon Knight OmniOutliner 3 for Mac 1 2007-12-02 05:29 AM


All times are GMT -8. The time now is 03:50 PM.


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