Hi everyone,
I have a script in which I can find price tags in QuarkXPress in text boxes and change it via Applescript (and Applescript toolbox for the regex).
I get this with the big help of 2 very kind members of this community “DJ Bazzie Wazzie” & “Yvan Koenig”. Thanks again for it
I wanted to extend the script with the ability to find price tags in tables in specific columns to change it via regex, but i get stucked wit it. Try everything I could to get this specific column. I managed to count the tables in the document and the columns of each table.
Here is the Script so far (working with text boxes!):
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()
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-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, "000,00 €")
end repeat
end if
end repeat
end processOpenDocument
-------------------------------------------------------------
-- 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
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
Hopefully somebody can help to change texts in a specific column (with always the same header!).
Here is a screenshot of a table:
The count of columns can vary between 10 to 13. The column with the “Preis” header is not always on the same position.
Thanks in advance for any help.
Model: Mac Pro (Early 2009)
AppleScript: 2.2.1
Browser: Safari 537.36
Operating System: Mac OS X (10.7)