Script for Find/Change

Joined
Dec 15, 2005
Messages
5
Reaction score
1
Points
3
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?
 
Joined
Jun 6, 2006
Messages
1,153
Reaction score
94
Points
48
Your Mac's 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 :)
 
OP
L
Joined
Dec 15, 2005
Messages
5
Reaction score
1
Points
3
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).
 
OP
L
Joined
Dec 15, 2005
Messages
5
Reaction score
1
Points
3
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?
 
OP
L
Joined
Dec 15, 2005
Messages
5
Reaction score
1
Points
3
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?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top