in

Quark Forums

Hi....How to read the XTags in QuarkXPress using apple scrip

Last post 05-12-2008 9:45 AM by Ravi. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-27-2008 5:38 AM

    Hi....How to read the XTags in QuarkXPress using apple scrip

    Hi....I need a apple script that will read the XTags in a Quark document 6.5. All i need is to find some text in Xtag and replace that with some other text....

    Please send me the script as soon as possible....

    Thanks in advance....

    Regards,
    Poovili.
  • 05-12-2008 6:42 AM In reply to

    • Ravi
    • Top 100 Contributor
    • Joined on 01-11-2006
    • Posts 106

    Hi....How to read the XTags in QuarkXPress using apple scrip

    Hello Poovili,

    You can use simple find and replace function of word or text edit to replace the word correct?
  • 05-12-2008 8:28 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,184

    Hi....How to read the XTags in QuarkXPress using apple scrip

    Ravi is right - but you won't be able to read XPress Tags within a Quark document. You have to save as text with XPress Tags first, then do the search and replace, then put the text back in.

    Have a look at this. I've put in a few explanations but ask if you don't understand!

    set my_path to (path to desktop folder from user domain) as string
    set export_file to my_path & "ExportedText"
    set new_file to my_path & "CleanedText"

    --this part saves story 1 as an XPress Tags file, named ExportedText
    tell document 1 of application "QuarkXPress"
         tell story 1
              save it in file export_file as "XPress Tags"
         end tell
    end tell

    --now for the search and replace routines, which run on the exported text file
    copy (read file export_file) to the_text
    set fileref to open for access new_file with write permission

    -- Put the search and replace strings in here. Copy the line and put in as many as you like.
    set the_text to replace_chars(the_text, "the text to look for", "the text to replace it with")

    -- Now the edited file is saved as "CleanedText"
    write the_text starting at eof to fileref
    close access fileref


    -- Write the edited file back into story 1
    tell application "QuarkXPress"
         set properties to {import styles:true}
         tell document 1
              set story 1 to file new_file --re-import the text
         end tell
    end tell

    --now delete the text files, otherwise subsequent runs will add to them!
    tell application "Finder"
         delete file export_file
         delete file new_file
    end tell

    display dialog "DONE"

    -- this routine does the search and replace work for you
    on replace_chars(this_text, search_string, replacement_string)
         set item_count to 10
         repeat until item_count = 1
              set AppleScript's text item delimiters to the search_string
              set the item_list to every text item of this_text
              set item_count to length of item_list
              set AppleScript's text item delimiters to the replacement_string
              set this_text to the item_list as string
              set AppleScript's text item delimiters to ""
         end repeat
         return this_text
    end replace_chars
  • 05-12-2008 9:45 AM In reply to

    • Ravi
    • Top 100 Contributor
    • Joined on 01-11-2006
    • Posts 106

    Hi....How to read the XTags in QuarkXPress using apple scrip

    Thanks Emma for the detailed AS

    Ravi
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems