Applescript to deal with diacritics

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
rgbherman
Posts: 0
Joined: 15 Jan 2007, 14:37

Applescript to deal with diacritics

Post by rgbherman » 27 Feb 2013, 08:27

My Applescript-Quark skills are barely beyond the basics... My first participation in this forum. I need to export content out of Quark on an ongoing basis. There are many diacritics that once out of Quark are not readable because they are in a Diacritical font that doesn't export (in fact even the clipboard "sees" the letters as something different than is displayed in Quark). So I need to change the diacritics while in Quark to something that plays nice downstream and can be scripted in TextWrangler to unicode (which is easy!).Two examples in unicode: and Here is my hobbled together attempted script for the .tell application "QuarkXPress"activateset theRanges to (object reference of every text style range where the font is "Diacritical-Regular" and contents is "")set rangeCount to count of items of theRangesrepeat with thisItem from 1 to rangeCountset contents of item thisItem of theRanges to ("u " where the font is "Times New Roman")end repeatend tellThis is error message:error "QuarkXPress got an error: Cant get object reference of every text style range whose font = \"Diacritical-Regular\" and contents = \"\"." number -1728 from object reference of every text style range whose font = "Diacritical-Regular" and contents = ""

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Applescript to deal with diacritics

Post by Emma » 27 Feb 2013, 23:24

First things first: Scope!
You need to get some understanding of the hierarchy of objects in Quark. Mine is sketchy, so if I make mistakes, I hope someone will correct me!
Your script currently addresses the Application Quark (tell application "QuarkXPress"). The application properties are general things such as layout preferences, language.
You need first and foremost to address your script to the Document, so change your first line to:
tell document 1 of application "QuarkXPress"
However, even 'document' doesn't understand 'text style ranges'. So you'll need to add something like:
tell text box 1
...
end tell
Next problem: I don't think text style ranges include content - they are about style. If you take out the 'and contents is...' you will find that this line works.
Next problem: in the 'set contents' line, you can't have a 'where the font is'. You've already established that the font in theRanges is Diacritical, so this is meaningless.
Your best approach is to start a new script and build it a bit at a time, testing as you go along. First, get a script that will identify your text ranges (the suggestions I've made above should get you that far). Then, try and get it to identify the characters you want to change.
Come back when you've got a bit further, if there are more issues.
PS If you can use a different browser, you will get line returns and your posts will be much easier to read! Annoying, I know. Firefox works, I keep it solely for posting on here!

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Applescript to deal with diacritics

Post by Emma » 27 Feb 2013, 23:34

Just tested this line and it works:
set theRanges to (object reference of every text where it is "")

Important thing: if you're replacing text with something of a different length, make sure you do it starting from the end - otherwise 'character 50' will become 'character 66' and your ranges will be meaningless!
Like this:
repeat with thisItem from rangeCount to 1 by -1
set contents of item thisItem of theRanges to ("u ")
end repeat

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Applescript to deal with diacritics

Post by Emma » 27 Feb 2013, 23:41

Can you make a brief list of what you actually want the script to do? Does the Diacritical font actually matter, or is it the character which is important? Presumably you won't have in another font, for example?

rgbherman
Posts: 0
Joined: 15 Jan 2007, 14:37

Applescript to deal with diacritics

Post by rgbherman » 28 Feb 2013, 07:33

Attempting to simplify and clarify and using Firefox as recommended:
Here is a script that runs without error but doesn't yet offer the solution needed. (The list will get longer as we identify all the problem characters.)
tell document 1 of application "QuarkXPress"
set (every text of every story where it is "`") to ""
set (every text of every story where it is "") to ""
set (every text of every story where it is "") to ""
set (every text of every story where it is "") to ""
set (every text of every story where it is "") to ""
set (every text of every story where it is "") to ""
set (every text of every story where it is "") to ""
end tell
The script has to set the search font to "Diacritical-Regular". I have determined that the replacement font doesn't matter as long as it is not "Diacritical-Regular".
I need to run this on old files that may or may not have the characters. If a particular character doesn't exist in the document I get this error:
error "QuarkXPress got an error: Cant set every text of every story of document 1 whose it = \"\" to \"\"." number -10006 from every text of every story of document 1 whose it = ""
So I have two issues to solve....

rgbherman
Posts: 0
Joined: 15 Jan 2007, 14:37

Applescript to deal with diacritics

Post by rgbherman » 28 Feb 2013, 07:48

Just in case you can't focus on this because it makes no sense: For many years, there was a problem with the special fonts we were using not offering some of the more "exotic" diacriticals. The problem was solved by creating the letters (in Fontographer maybe?) and putting them in character slots in the Diacritical font. At the time that must have seemed like an ingenious solution but now of course it is a vexing problem because simple searches like the ones in the script above would change letters that need to stay as is--unless you can specify the search font as Diacritical.

Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Applescript to deal with diacritics

Post by Jean-Marie Schwartz » 28 Feb 2013, 22:12

May I pop in?
Question 1 is: Do you absolutely need a script? It is scriptable but just to make sure. Question 2 is: you can perform a search on (among others) font. So if you simply need to change every text whose font is "Diacritical" to say "Adobe Garamond Pro", the Search and Replace pane will do that. Just enable more options to searching.
Well if you really need to script it all, my next question would be: Is it imaginable to first change every text whose font is "Diacritical" to whatever font you wish (provided it is a single one)? If answer is yes, then you can run this code:
tell application "QuarkXPress95"
tell document 1
tell every story
tell (every text style range whose font is "Diacritical")
set font to "Adobe Garamond Pro"
[b]end [b]tell
[b]end [b]tell
[b]end [b]tell
[b]end [b]tell

Then you can perform your Search and Replace loop. Come back if you have further questions.

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Applescript to deal with diacritics

Post by Emma » 01 Mar 2013, 00:25

Jean-Marie has a very good point - Quark's find/replace dialogue covers this well, but if there's a lot of characters to replace and a lot of files to work on, it makes sense to script it for speed.
As for the 'error if character not found' - you can surround each step with:
try...
end try
However this would get very messy for each line. So if you have a command that works, I suggest you wrap it up in a subroutine like this:
replaceChars("a", "b")

on replaceChars(char_to_find, char_to_replace)

tell document 1 of application "QuarkXPress"

try
set (every text of every text flow where it is char_to_find) to char_to_replace
end try

end tell

end replaceChars


-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

For some reason my Quark won't accept the word 'story' but is happy with 'text flow'. Not sure if this makes a difference?

rgbherman
Posts: 0
Joined: 15 Jan 2007, 14:37

Applescript to deal with diacritics

Post by rgbherman » 01 Mar 2013, 04:54

Yes, I can see that "try" will deal with the one issue. Thanks for helping me understand that.

A manual find/replace is not attractive at all. Scripting will save much, much time.
By simply searching and changing the diacritical font,as explained in the earlier post (yesterday's in-house "smart" solution=today's problem), the result will be characters that areincorrect. That is, for example, the ligature character fi will appear in places that it needs to be like "first" and in places it does not and where you actually want a "". BIG problem.

The script needs to "set the search font" in order for this to work. If that hurdle can be cleared, this will be run on many hundreds of files over the next couple of years and save much angst.

Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Applescript to deal with diacritics

Post by Jean-Marie Schwartz » 01 Mar 2013, 05:55

Not sure I get it all. Is Diacritical font used for chars to be changed and only that? I mean any char set in Diacritical must be changed to another font AND every char toi be changed is set in Diacritical? In your example: is the word "first" set all in Diacritical?

Post Reply

Return to “QuarkXPress 8, 9 & 10: AppleScript”