Results 1 to 5 of 5
  1. #1
    Script for Find/Change

    Member Since
    Dec 15, 2005
    Posts
    5
    Script for Find/Change
    Hi everyone,

    I'm working on QuarkXpress Passport 6.5 and frequently get DOS-coded
    texts, so I need a script to replace some characters without altering
    the style of them.
    Here's my first try (yes, I'm a noob in scripting...):

    Code:
    tell document 1 of application "QuarkXPress Passport"
           activate
           tell current box
                   tell story 1
                           repeat with i from 1 to count characters
                                   tell character i
                                           if it is "º" then
                                                   set contents to "§"
                                           else if it is "ã" then
                                                   set contents to "["
                                           else if it is "˛" then
                                                   set contents to "\\"
                                           else if it is "ª" then
                                                   set contents to "±"
                                           else if it is "˚" then
                                                   set contents to "|"
                                           else if it is "Ã" then
                                                   set contents to "{"
                                           end if
                                   end tell
                           end repeat
                   end tell
           end tell
    end tell
    And surprizingly it works. But it's very-very-very slow...
    Is there a way to make a (much more) faster script for this job?

  2. #2
    Script for Find/Change
    cazabam's Avatar
    Member Since
    Jun 06, 2006
    Posts
    1,153
    Specs:
    MacBook 2.0GHz White, 512MB RAM, 60GB HDD
    Hmm ... normally I would just suggest using translations or regular expressions, but applescript supports neither of these. I would recommend search for search/replace functions, though. Google seems to return a few hits, but not being too familiar with applescript I wouldn't want to presume to be able to pick the best :-)

  3. #3
    Script for Find/Change

    Member Since
    Dec 15, 2005
    Posts
    5
    I found some scripts on the net for find/replace and they are fast enough. But the problem is that those scripts work by copy/pasting the text throu memory and this way all the formatting is lost (i.e. if the first character of the first paragraph is bold, the whole resulting text will be bold).

  4. #4
    Script for Find/Change

    Member Since
    Dec 15, 2005
    Posts
    5
    After a little research I came up with this one:
    Code:
    tell document 1 of application "QuarkXPress Passport"
           activate
           tell every story
                   try
                          set contents of every character whose contents is "º" to "§"
                   end try
                   try
                          set contents of every character whose contents is "ã" to "["
                   end try
                   try
                          set contents of every character whose contents is "˛" to "\\"
                   end try
                   try
                          set contents of every character whose contents is "ª" to "±"
                   end try
                   try
                          set contents of every character whose contents is "˚" to "|"
                   end try
                   try
                          set contents of every character whose contents is "Ã" to "{"
                   end try
           end tell
    end tell
    And it's pretty fast.
    But it has a major problem: the every character whose contents is "ã" is interpreted strangely as every character that is "a" or "A" or "ã" or "Ã" or "â" or "Â" etc. Even adding the lines "considering case" and "considering diacritics" doesn't help.
    Any ideas?

  5. #5
    Script for Find/Change

    Member Since
    Dec 15, 2005
    Posts
    5
    Problem solved!
    Here's the source of it if anybody needs such a script:
    Code:
    Replace("ã", "[")
    Replace("Ã", "{")
    Replace("º", "§")
    Replace("ª", "±")
    Replace("?", "\\")
    Replace("?", "|")
    
    on Replace(searchstring, replacestring)
    	tell document 1 of application "QuarkXPress Passport"
    		activate
    		tell every story
    			considering diacriticals
    				considering case
    					try
    						set (every text where it is searchstring) to replacestring
    					end try
    				end considering
    			end considering
    		end tell
    	end tell
    end Replace
    It runs pretty fast and there are no longer case- and diacritics-related problems.
    But it was very hard to make this script without documentation. BTW, does anybody know where could I find some documentation for QuarkXpress scripting?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. shell script to find filenames with accented characters
    By pennerk in forum OS X - Operating System
    Replies: 0
    Last Post: 08-16-2012, 07:13 PM
  2. how i can change and find where my mac localized to...
    By hoiphuoc in forum OS X - Operating System
    Replies: 1
    Last Post: 02-15-2011, 08:31 PM
  3. How to batch find/change html documents
    By Noriker in forum Web Design and Hosting
    Replies: 1
    Last Post: 09-10-2010, 06:36 PM
  4. Change I.P address script?
    By trini_pirate in forum OS X - Operating System
    Replies: 0
    Last Post: 05-26-2008, 01:59 PM
  5. Writing a script to change browser preferences - Help
    By ysuee in forum OS X - Operating System
    Replies: 0
    Last Post: 01-22-2004, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •