Applescript Error 1728 - text can't be changed in Quark document

Hi,

everything works fine with the script except at one position and I can’t find out what is different to the other text passages.

The offset is right, but in the moment the text should be changed it seems off of the offset.

The script changes text in a QuarkXPress document in QuarkXPress 8.5.1.

I get the error that a text can’t be changed. I don’t know why.


Here is the complete Script:


set theFolder to (choose folder) as string
set theFiles to paragraphs of (do shell script "ls " & quoted form of POSIX path of theFolder)
repeat with i from 1 to count theFiles
	repeat 1 times --to simulate continue
		set theFile to theFolder & item i of theFiles as string
		if theFile does not end with ".qxd" then
			exit repeat -- simulate a continue command
		end if
		openFile(theFile)
		-- if number of document = 0 the file isn't opened
		if nrOfOpenDocuments() is 0 then
			exit repeat -- simulate a continue command
		end if
		processOpenDocument()
		processColoredText()
		closeAndSaveDocument(theFile)
	end repeat
end repeat

on processOpenDocument()
	repeat with storyIndex from 1 to countStories()
		set theStory to getStoryContents(storyIndex)
		set priceOffsets to AST find regex "[0-9]{0,1}[.]{0,1}[0-9X]{1,3},[0-9X]{2}" in string theStory with returning offsets
		if priceOffsets is not missing value then
			-- reverse the list, edit from end to front so the offsets stays correct
			set priceOffsets to reverse of priceOffsets
			repeat with priceRange in priceOffsets
				set foundString to getRangeOfStory(storyIndex, rm_so of priceRange, rm_eo of priceRange)
				setRangeOfStory(storyIndex, rm_so of priceRange, rm_eo of priceRange, "xx,xx")
			end repeat
		end if
	end repeat
end processOpenDocument

on processColoredText()
	tell application "QuarkXPress"
		tell document 1
			if not (exists (color spec "preisgruen")) then
				make color spec at end with properties {name:"preisgruen", CMYK color value:{45875, 0, 65535, 0}, separation:true}
				-- 0% = 0 | 100% = 65535
			end if
			do updates
			set cstyles to name of every character spec
			if "7 TEXT 4 PREIS" is in cstyles then
				set color of character spec "7 TEXT 4 PREIS" to "preisgruen"
			end if
			if "5,5 Text 4 PREIS " is in cstyles then
				set color of character spec "5,5 Text 4 PREIS " to "preisgruen"
			end if
		end tell
	end tell
end processColoredText
-------------------------------------------------------------
-- QXP HANDLERS
-------------------------------------------------------------

on nrOfOpenDocuments()
	tell application "QuarkXPress" to return count of documents
end nrOfOpenDocuments

on openFile(thePath)
	tell application "QuarkXPress" to open alias thePath with Suppress All Warnings
end openFile

on closeAndSaveDocument(thePath)
	tell application "QuarkXPress" to close document 1 with saving
end closeAndSaveDocument

on countStories()
	tell application "QuarkXPress"
		tell document 1 to return count of stories
	end tell
end countStories

on getStoryContents(i)
	tell application "QuarkXPress"
		tell document 1 to return contents of story i
	end tell
end getStoryContents

on setRangeOfStory(i, s, e, t) -- index, start range, end range, text
	tell application "QuarkXPress"
		tell document 1 to set text of characters s thru e of story i to t
		-- tell document 1 to set properties of characters s thru e of story i to {color:red}
	end tell
end setRangeOfStory

on getRangeOfStory(i, s, e) -- index, start range, end range
	tell application "QuarkXPress"
		tell document 1 to return characters s thru e of story i
	end tell
end getRangeOfStory

-------------------------------------------------------------
-- MISCELLANEOUS HANDLERS
-------------------------------------------------------------
on getPathsFromFolder()
	set rawData to do shell script "ls " & quoted form of POSIX path of inPath
	set theFileNames to AST find regex "([^" & return & "]+)($|" & return & ")" in string rawData regex group 2
	
	repeat with x from 1 to count theFileNames
		set item x of theFileNames to inPath & item x of theFileNames
	end repeat
	return theFileNames
end getPathsFromFolder

Does anybody know what goes wrong? If this is not a script problem, is there a way to get over this error and continue with the rest of the document?

Thanks on advance for your help.

Model: Mac Pro (Early 2009)
AppleScript: 2.2.1
Operating System: Mac OS X (10.7)

Replace this:
set every text of characters 96 thru 100 of story 155 of document 1 to “xx,xx”

with this:
set characters 96 thru 100 of story 155 of document 1 to “xx,xx”

HTH.

Thank you CMYS. This is working but with one little problem.

I get no error, but instead of replacing “14,90” to “xx,xx” it replaces like this “14xx,xx €”.

I don’t understand why the offset seems right and in the moment it should replace the whole price “14,90 €” it only tries to replace “,90 €”!?

I still have this problem with a few text fields in QuarkXPress and unfortunately still no clue what is the reason for this behavior :frowning:

Any help is really appreciated.

THANKS in advance.