| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Dec 15, 2005
Posts: 5
![]() |
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
Is there a way to make a (much more) faster script for this job? |
| QUOTE Thanks | |
![]() Member Since: Jun 06, 2006
Posts: 1,153
![]() ![]() ![]() ![]() ![]() ![]() Mac 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 :-)
|
| QUOTE Thanks | |
![]() Member Since: Dec 15, 2005
Posts: 5
![]() |
|
||||
| QUOTE Thanks | |||||
![]() 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
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 | |
![]() Member Since: Dec 15, 2005
Posts: 5
![]() |
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
But it was very hard to make this script without documentation. BTW, does anybody know where could I find some documentation for QuarkXpress scripting? Last edited by Lorand; 06-19-2006 at 05:58 AM. |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
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 03:15 AM.
Powered by vBulletin