Runs OK as plain text .applescript (and in SD) but not as compiled script .scpt in FInder-why?


(Bret Perry) #1

Why won’t this run successfully as a compiled script in InDesign (Finder)?
Works great as plain text .applescript in InDesign (Finder)?

InDesign Applescript to create data merge placeholders for images.

Same code saved as compiled .scpt gives “Error 0 no error code” on first run and no feedback, no results on subsequent runs.
Also runs fine and works with no errors in Script Debugger or Script Editor but not as “stand-alone” .scpt

Here is an .idml file with data that works with the script:
test datamerge picture box only.idml

--make data merge placeholders for images in Adobe InDesign
--datasource must be set in data merge panel of frontmost document
--image frames must be rectangles and have a script label set to data merge image field name
--load data source before running script

set dataImage to {}
tell application "Adobe InDesign CC 2014"
	set myFields to field name of every data merge field of data merge 1 of document 1
	set myFieldCount to count of myFields
	set DMprop1 to properties of every data merge field of data merge 1 of document 1
	--make dataImage a list of data merge fields with images
	repeat with thisField from 1 to myFieldCount
		if (field type of item thisField of DMprop1 as string) contains "image" then copy (thisField as integer) to end of dataImage
	end repeat
	--Make datamerge image placeholders for page items
	tell document 1
		repeat with thisImageSet from 1 to (count of dataImage) --dataImageCount of (dataImage as list)
			set allRect to (every rectangle whose label is (item (item thisImageSet of dataImage as integer) of myFields))
			repeat with thisRect in allRect
				set myImagePlaceholder to make new data merge image placeholder with properties {field:(object reference of data merge field (item thisImageSet of dataImage as integer) of data merge 1), placeholder page item:thisRect}
			end repeat --iterate through each rectangle
		end repeat --each field in dataImage
	end tell
end tell --app 1

Datamerge properties in CC do seem a bit wonky. Index fileds are wrong and some other properties that worked in old versions are not availablle anymore at document level so I rewrote it to fix and now it works great but only when saved as palin text .applescript.

Any idea why or if I can fix it to run no matter how it’s saved?