View Single Post
I'm having some problems with a script I'm writing. The idea is to have a script that will create a series of tasks automatically by incrementing a number. For example, say you have a homework set to do for school, and it's problems 1 through 10, if you want one action for each problem, rather than spending a lot of time creating 10 actions (the problem gets worse as the number of problems increases), I want to have a script that automates the process. Here is what I have so far:

Code:
tell application "OmniFocus"
	tell front document
		tell (first document window whose index is 1)
			try
				set actionTitle to display dialog "Title for action, sequence number will appear at end" default answer "Problem #"
			on error
				return
			end try
			
			try
				set startingIndexResponse to display dialog "Enter starting index number" default answer "1"
				set startingIndex to startingIndexResponse's text returned as integer
			on error
				return
			end try
			
			try
				set endingIndexResponse to display dialog "Enter ending index number" default answer "10"
				set endingIndex to endingIndexResponse's text returned as integer
			on error
				return
			end try
			
			set actionLocation to tasks of containing project of value of selected trees of content
			set i to 0
			repeat with i from startingIndex to endingIndex
				set newAction to make new task with properties {name:(actionTitle & (i as rich text))}
				move newAction to end of actionLocation
			end repeat
			
		end tell
	end tell
end tell
I get various errors with the loop depending on how I vary the code. As it appears this will generate an error of

Code:
make new task with properties {name:{text returned:"Problem #", button returned:"OK", «class ktxt»:"1"}}
		"OmniFocus got an error: Can’t make or move that element into that container."
but if I change the code to specify a location when creating the new task I get an error about the specifier for the location:

Code:
make new task at end of {{task id "pOhErpXJ0v0" of document id "cIQtWwBZUKy", task id "orFUBtat5ex" of document id "cIQtWwBZUKy", task id "nYSFQypfzJG" of document id "cIQtWwBZUKy", task id "dna1GTquTdK" of document id "cIQtWwBZUKy", task id "aEUL_tWw8bq" of document id "cIQtWwBZUKy", task id "hIG8Rsv8Dbe" of document id "cIQtWwBZUKy", task id "bDFT5oCOnX9" of document id "cIQtWwBZUKy", task id "nUat8J3olgG" of document id "cIQtWwBZUKy", task id "cCm91x5tbhl" of document id "cIQtWwBZUKy", task id "hpap4LrBsGO" of document id "cIQtWwBZUKy", task id "izNkHuwo8jQ" of document id "cIQtWwBZUKy", task id "bGGNL_c6orr" of document id "cIQtWwBZUKy", task id "i2-Kf91D-kh" of document id "cIQtWwBZUKy", task id "docgQELzizB" of document id "cIQtWwBZUKy", task id "akjn2qZwC3R" of document id "cIQtWwBZUKy", task id "jwMA1ZkANaH" of document id "cIQtWwBZUKy"}} with properties {name:{text returned:"Problem #", button returned:"OK", «class ktxt»:"1"}}
		"OmniFocus got an error: Can’t make {{task id \"pOhErpXJ0v0\" of document id \"cIQtWwBZUKy\", task id \"orFUBtat5ex\" of document id \"cIQtWwBZUKy\", task id \"nYSFQypfzJG\" of document id \"cIQtWwBZUKy\", task id \"dna1GTquTdK\" of document id \"cIQtWwBZUKy\", task id \"aEUL_tWw8bq\" of document id \"cIQtWwBZUKy\", task id \"hIG8Rsv8Dbe\" of document id \"cIQtWwBZUKy\", task id \"bDFT5oCOnX9\" of document id \"cIQtWwBZUKy\", task id \"nUat8J3olgG\" of document id \"cIQtWwBZUKy\", task id \"cCm91x5tbhl\" of document id \"cIQtWwBZUKy\", task id \"hpap4LrBsGO\" of document id \"cIQtWwBZUKy\", task id \"izNkHuwo8jQ\" of document id \"cIQtWwBZUKy\", task id \"bGGNL_c6orr\" of document id \"cIQtWwBZUKy\", task id \"i2-Kf91D-kh\" of document id \"cIQtWwBZUKy\", task id \"docgQELzizB\" of document id \"cIQtWwBZUKy\", task id \"akjn2qZwC3R\" of document id \"cIQtWwBZUKy\", task id \"jwMA1ZkANaH\" of document id \"cIQtWwBZUKy\"}} into type specifier."
and this seems to happen no matter how I try to give the specifier for the location. Any tips on what I'm doing wrong? It seems to me like this should be a relatively simple script to write, but getting the location for the new task right appears to be quite a problem.