Wow! Thanks a lot. Very thankful for that DJ Bazzie Wazzie
This is working with 1 open qxp document, but with a little change. As it is possible to use regex, I changed the line like below:
set priceOffsets to AST find regex "[0-9]{1,3},[0-9]{2} ââÂŹ" in string theStory with returning offsets
And I removed the security check, as the found string is something else.
Maybe I described it wrong before ? is a placeholder cmd in QuarkXPress find & replace for any single character. This means if you do a find in QuarkXPress with ???,?? it will find any sequence like 123,45 or abc,de or a1b,2c.
Now using regex is much better and preferred by me.
Now I tried to combine it with the ability to make it work with a couple qxp documents, which should be saved and closed afterwards like in my initial applescript (see first post).
No luck so far, I get the open folder dialogue, but then it should open 1 qxp document after another and change the prices, saving and closing the document.
My tries end with an syntax error:
âendâ was expected, but âonâ was found
I am surely do something wrong by combining those functions. :rolleyes:
Here is what i tried:
--choose directory containing quark files
tell application "Finder"
activate
set source_folder to choose folder with prompt "Select folder:"
set source_files to (files of entire contents of source_folder whose file type is "XPRJ")
set source_files to sort source_files by name
set source_files to (sort source_files by name) as alias list
end tell
--loop through quark documents
repeat with storyIndex from 1 to countStories()
set theStory to getStoryContents(storyIndex)
set priceOffsets to AST find regex "[0-9]{1,3},[0-9]{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, "000,00 ââÂŹ")
end repeat
end if
end repeat
tell application "QuarkXPress"
activate
repeat with i from 1 to length of source_files
set quarkfile to item i of source_files
open quarkfile as alias use doc prefs yes remap fonts no without reflow
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
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
save document 1
close document 1 saving no
end repeat
end tell
I can only thank for any help and especially for your help DJ Bazzie Wazzie.