Applescript InDesign Grep Script - Needs updating

Hi All.

I had an applescript that was working in Indesign 2015, however, I’ve returned to use it with Indesign 2018 and it keeps intermittently failing.

The script would set find / change values, search the doc and return the text found, I would then use this text to form the file name for saving.


tell application "Adobe InDesign CC 2015"
	activate
	
	set myFindGrep to ".+"
	set mySelectedParaStyle to "DM Product Code Split"
	--
	--
	set find what of find grep preferences to myFindGrep
	set applied paragraph style of find grep preferences to mySelectedParaStyle as string
	--
	--
	set MyFoundWords to find grep
	--
	--
	repeat with i from 1 to count MyFoundWords
		set MyFoundWordsList to MyFoundWordsList & item i of MyFoundWords
	end repeat
	--
	set lastInList to count MyFoundWordsList
	
	set mySave to (myDesktopJobFolderPath & (item lastInList of MyFoundWordsList) & ".indd")
	
end tell


I’m getting a couple of different errors on the line…

set MyFoundWordsList to MyFoundWordsList & item i of MyFoundWords

Error 1:
Can’t make text from character 1 to character 8 of story id 332 of document id 603 of application “Adobe InDesign CC 2018” into type vector.

Error 2:
Can’t make text from character 1 to character 6 of story id 331 of document id 611 of application “Adobe InDesign CC 2018” into type vector.

The text it’s searching is just alpha/numeric codes, no special characters.

thanks

Shane

Hi. If the problem is intermittent and didn’t occur with the prior version, it could be a bug, however, the variable, MyFoundWordsList, isn’t defined in your posted code, and the erroring line actually shouldn’t exist; remove the repeat loop and change the preceding line to:

[format] set MyFoundWords to (find grep)'s contents
[/format]

Hi Marc

Thanks for the reply.

Apologies, I pulled this from a bigger script and left out the setting of ‘MyFoundWordsList’

I’ve tried adding your line, but I receive an error of…

Can’t make item 0 of {} into type Unicode text.

Like you say it could just be a bug in the newer versions of ID, I just can’t figure out why it’s erroring on some text and not others.

All sorted, a restart has fixed it :rolleyes: