InDesign Script worked before, now getting 1728 error

Hi,
I’ve had a script working fine. I’m in Yosemite and it worked fine in that OS, but there have been updates. I have yet to upgrade the OS to a new version, so I can work with InDesign CS6

This script was working up until a month ago:


global WordDocName
global wrongText
global myStories
--set uniqueInCopyStories to {}
--set wrongText to "BASE"


set theDoc to choose file without multiple selections allowed
set theDocInfo to info for theDoc
set theDocName to name of theDocInfo
set theDocName to characters 1 thru -6 of theDocName as text
set WordDocName to theDocName
set theDocName to theDocName & return

set myStories to {}

my processFiles(theDoc)

set mylist to items 1 thru -1 of myStories

set firstList to mylist

set secondList to RemoveDuplicates(firstList)

--secondList --> {1, 2, 3, 4}



set mynewlist to {}
repeat with i from 1 to (count of secondList)
	set myitem to item i of secondList as text
	set end of mynewlist to myitem
end repeat

set mystring to mynewlist as string
--return mystring

my processWordDoc(theDocName, mystring, WordDocName)

on processFiles(theDoc)
	
	tell application "Adobe InDesign CS6"
		activate
		open theDoc
		
		tell theDoc
			set myPages to every page
			repeat with i from 1 to count of myPages
				tell item i of myPages
					set myTextFrames to (every text frame of item i of myPages)
					repeat with aTextFrame in myTextFrames
						if item link of parent story of aTextFrame is not nothing then
							if parent story's item link's link type of aTextFrame is "InCopyMarkup" then
								set mystorytitle to story title of aTextFrame's parent story
								set myLabel to label of aTextFrame
								set myText to characters 1 thru -1 of mystorytitle as string
								--if myText does not contain wrongText then
								
								set myStory to aTextFrame's parent story's contents
								copy "Page " & (name of item i of myPages) & " " & mystorytitle & return & myLabel & return & myStory & return & return to end of myStories
							end if
						end if
						--end if
					end repeat
				end tell
			end repeat
		end tell
	end tell
	
	
end processFiles

on processWordDoc(theDocName, mystring, WordDocName)
	tell application "Microsoft Word"
		activate
		set newDoc to make new document
		copy styles from template active document template ¬
			"Macintosh HD:Users:Shared:headings.dotm"
		copy theDocName & mystring to content of text object of newDoc
		save as active document file name WordDocName
		my textblue()
		
	end tell
end processWordDoc

on textblue()
	with timeout of 60000 seconds
		tell application "Microsoft Word"
			set myPars to every paragraph of active document
			set myTitle to text object of paragraph 1 of active document
			set color index of font object of myTitle to blue
			repeat with aPar in myPars
				if content of text object of aPar starts with "Page" then
					
					set myRange to text object of aPar
					
					set color index of font object of myRange to blue
				end if
			end repeat
		end tell
	end timeout
end textblue

on RemoveDuplicates(inputList)
	
	set outputList to {}
	
	repeat with i from 1 to length of inputList
		
		--    We make testItem a single-item list to ensure
		--    that sublists of the inputList are properly
		--    looked for in the outputlist.
		--
		set thisItem to item i of inputList
		set testItem to {thisItem}
		
		if (outputList does not contain testItem) then
			
			set end of outputList to thisItem
			
		end if
		
	end repeat
	
	return outputList
	
end RemoveDuplicates

Now there is a compile error when the script gets to page in this handler:


on processFiles(theDoc)
	
	tell application "Adobe InDesign CS6"
		activate
		open theDoc
		
		tell theDoc
			set myPages to every page

It says it was expecting a class but found an identifier–which is wrong because “page” is a class.

I’ve tried to save the script as text, then open that text in Applescript and recompile (internet suggestion) but that does not work. Please help.

Are you sure that the script which behaved well some times ago is exactly the one which you post.

on processFiles(theDoc)
	
	tell application "Adobe InDesign CS6"
		activate
		open theDoc
		
		--tell document theDoc # theDoc is a pathname. I'm not sure that it may be used as a document descriptor
		tell document 1 -- I'm not sure that it's the correct syntax for inDesign but it would resemble to that
			set myPages to every page

Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mercredi 23 novembre 2016 21:28:20

Well, I got the script to compile by adding a tell block


tell application "Finder"
	activate
set theDoc to choose file without multiple selections allowed
set theDocInfo to info for theDoc
set theDocName to name of theDocInfo
set theDocName to characters 1 thru -6 of theDocName as text
set WordDocName to theDocName
set theDocName to theDocName & return

end tell


So it runs up to the point where InDesign CC is supposed to open theDoc, but instead I am getting this error:
error “Adobe InDesign CC 2017 got an error: Cannot handle the request because a modal dialog or alert is active.” number 30486

There are no modal dialog or alert, so this is a mystery. I did try this:

tell application "Adobe InDesign CC 2017"
		set user interaction level of script preferences to never interact
		try
			activate
			open theDoc
			
		end try
		set user interaction level of script preferences to interact with all

to no avail.

Arrgh

Browser: Safari 537.36
Operating System: Mac OS X (10.10)

Hi. Your tell block adjustment now incorrectly sends calls that belong to standard additions to the Finder, which is only useful, here, to extract the name. My suspicion with the modal error message is that the document has not been fully opened prior to receiving commands, and it may require a short delay. I don’t have your versions of InDesign or MacOS to check that theory. Using an explicit “get” against an object might also work. If I understand your code’s purpose, the InDesign portion could be shortened.

set theDoc to (choose file without multiple selections allowed)
tell application "Finder" to set theDocName to theDoc's name
set theDocName to theDocName's text 1 thru -6
set {WordDocName, theDocName} to {theDocName, theDocName & return}

set myStories to {}

tell application "Adobe InDesign CS3"
	tell (open theDoc) to repeat with aFrame in (get (pages's text frames whose parent story's item link's link type is "InCopyMarkup")'s parent story)
				tell aFrame to set myStories's end to "Page " & its index & " " & its story title & return & its label & return & its text & return & return
		
	end repeat
end tell

myStories

Thanks.