New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Script for Find/Change


Post Reply New Thread Subscribe

 
Thread Tools
Lorand

 
Member Since: Dec 15, 2005
Posts: 5
Lorand is on a distinguished road

Lorand is offline
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?
QUOTE Thanks
cazabam

 
cazabam's Avatar
 
Member Since: Jun 06, 2006
Posts: 1,153
cazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of light
Mac Specs: MacBook 2.0GHz White, 512MB RAM, 60GB HDD

cazabam is offline
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 :-)
QUOTE Thanks
Lorand

 
Member Since: Dec 15, 2005
Posts: 5
Lorand is on a distinguished road

Lorand is offline
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).
QUOTE Thanks
Lorand

 
Member Since: Dec 15, 2005
Posts: 5
Lorand is on a distinguished road

Lorand is offline
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?
QUOTE Thanks
Lorand

 
Member Since: Dec 15, 2005
Posts: 5
Lorand is on a distinguished road

Lorand is offline
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?
QUOTE Thanks

Post Reply New Thread Subscribe


« Can You Help? I've Messed Up Terminal.app Login | Skip Profile--Please Help »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Quick Apple Script Question ezhangin OS X - Development and Darwin 6 12-14-2005 09:30 PM
MacAddict Backup Script sevenhelmet OS X - Development and Darwin 7 09-18-2005 03:56 PM
Need some help on a unix script :-) starrin OS X - Operating System 0 12-01-2004 08:55 PM
Ooops - dragged a script to the Finder!! kjellquist OS X - Operating System 1 03-15-2004 06:46 PM
tsch script - nested loop dynamic variable reference lizardthefish OS X - Development and Darwin 0 03-04-2004 11:53 PM

All times are GMT -4. The time now is 09:44 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?