Replace ":" with non-breaking space + ":"

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
Vincent Nicolas
Posts: 0
Joined: 13 Apr 2011, 09:55

Replace ":" with non-breaking space + ":"

Post by Vincent Nicolas » 02 Sep 2011, 04:40

Hello,
Do you know how to script special Quark Character like non-breaking space... in Xpress Tag is

tell application "QuarkXPress"
activate
try
tell document 1
repeat with i from 1 to count of stories
tell story i
set (every text where it is ":") to "Non-breaking space + :"
end tell
end repeat
end tell
end try
end tell
Thanks for helping me
Happy Week-End
Vincent

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

Replace ":" with non-breaking space + ":"

Post by Emma » 02 Sep 2011, 04:48

I have a nasty feeling you can't script this directly within Quark. You have to export the text with XPress Tags, do the replace using a scriptable text editor and use for your non-breaking space. Then you re-import it. All of this can be done seamlessly in a script
It's actually easier than you might think. Tex-Edit Plus is brilliant and free (but not compatible with Lion??)
Unless they've added something? Let's hope so. I had one brilliant script that did lots of stuff like this and can post bits if they'd be useful.

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

Replace ":" with non-breaking space + ":"

Post by Emma » 02 Sep 2011, 05:15

In fact here is something I put together for someone on the forum a couple of years ago. I don't remember much about it but feel free to root through for useful bits. It doesn't even require a text editor!
set my_path to (path to desktop folder from user domain) as string
set export_file to my_path & "ExportedText"
set new_file to my_path & "CleanedText"

--this part saves story 1 as an XPress Tags file, named ExportedText
tell document 1 of application "QuarkXPress"
tell story 1
save it in file export_file as "XPress Tags"
end tell
end tell

--now for the search and replace routines, which run on the exported text file
copy (read file export_file) to the_text
set fileref to open for access new_file with write permission

-- Put the search and replace strings in here. Copy the line and put in as many as you like.
set the_text to replace_chars(the_text, "the text to look for", "the text to replace it with")

-- Now the edited file is saved as "CleanedText"
write the_text starting at eof to fileref
close access fileref


-- Write the edited file back into story 1
tell application "QuarkXPress"
set properties to {import styles:true}
tell document 1
set story 1 to file new_file --re-import the text
end tell
end tell

--now delete the text files, otherwise subsequent runs will add to them!
tell application "Finder"
delete file export_file
delete file new_file
end tell

display dialog "DONE"

-- this routine does the search and replace work for you
on replace_chars(this_text, search_string, replacement_string)
set item_count to 10
repeat until item_count = 1
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set item_count to length of item_list
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
end repeat
return this_text
end replace_chars


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

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

Replace ":" with non-breaking space + ":"

Post by Jean-Marie Schwartz » 02 Sep 2011, 06:09

The trick is to set a variable to the Unicode value of the space and of a word-joiner. Then simply run your search and replace routine. Here is what I have on my side:
property FineXPress : data utxt2009 as Unicode text -- U+2009; 0x2009; 8201
--property FineXPress : data utxt000F as Unicode text -- U+000F; 0x000F; 15
property Gluon : data utxt2060 as Unicode text -- U+2060; 0x2060; 8288
property Sixieme_de_cadratin : data utxt2006 as Unicode text -- U+2006; 0x2006; 8198
property Chevron_ouvrant : data utxt00AB as Unicode text -- U+00AB; 0x00AB; 171
property Chevron_fermant : data utxt00BB as Unicode text -- U+00BB; 0x00BB; 187

tell application "QuarkXPress9.1"
--activate
set the text of the selection to (Chevron_ouvrant & FineXPress & Gluon & the selection & FineXPress & Gluon & Chevron_fermant)
end tell


HTH. And hope you can cope with it. In case you need the code matching exactly what yu're after, just ask. Sorry it's time to leave now :-(

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

Replace ":" with non-breaking space + ":"

Post by Emma » 02 Sep 2011, 06:15

Jean-Marie, why didn't you tell me that years ago?? Brilliant tip. Still need to know Unicode for a non-breaking space, though....

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

Replace ":" with non-breaking space + ":"

Post by Jean-Marie Schwartz » 02 Sep 2011, 08:20

The non-breaking space doesn't seem to work properly in Quark (though I haven't checked Unicode for one I simply selected the one in Quark and got its Unicode value). I think I told you about the Unicode values a while back, but sometimes info is just coming at the wrong moment or not as accurate as one would expect. As for the word-joiner tip, I simply discovered it here some months ago. I can't remember who told me about it and I only understood or re-read or re-discovered its message much later! :-)
Oh! I suggest you install Unicode Checker, a free app to check everything you need about Unicode values, names, etc. Used along with (or better said alternately with) a simple AP to get the Unicode value of the selected glyph in Quark, it saved me hours of work already!
tell application "QuarkXPress"
get the unicode value of character 1 of the selection
display dialog ("Valeur Unicode du glyphe : " & result) buttons {"OK"} default button 1
end tell

Vincent Nicolas
Posts: 0
Joined: 13 Apr 2011, 09:55

Replace ":" with non-breaking space + ":"

Post by Vincent Nicolas » 04 Sep 2011, 22:34

Regarding the unicode variable, if I do the code below, the add in my texte the string "data utxt00AB" and no the character... Did I miss something ?
Thanks for helping me
Vincent

property Chevron_ouvrant : "data utxt00AB" as Unicode text
tell application "QuarkXPress"
activate
set after character 1 of the selection to Chevron_ouvrant
end tell

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

Replace ":" with non-breaking space + ":"

Post by Jean-Marie Schwartz » 04 Sep 2011, 23:18

The code I gave is supposed to: 1) set variables as property, such as Gluon (word-joiner), FineXPress (variable space in QuarkXPress), Chevron_ouvrant (French opening quotes), etc. as a property, the variable is set one time for the whole script; 2) it replaces the text of the selection with the text itself + French opening quotes and space and word joiner before it and space and word joiner and French closing quotes.
As for your code, it is incorrect. Set is a verb to put a value into a variable: set My_value to 6 > My_value = 6 as real number; set My_message to "Hi, I'm off till the end of the day. Please contact my coworkers." > My_message = the whole text as string; etc. In my case, Chevron_ouvrant is a variable containing the -glyph as Unicode text. So I can handle it later on much easier for the human reader (and coder) and everywhere I'll use it, the script will know that it is in fact the glyph to be used instead of the variable.
So if you want to add that glyph (it is the glyph as such, not the text "data utxt00AB"!!!) before the text of the selection, your code will go like this: set the text of the selection to (Chevron_ouvrant & the selection) provided the text is highlighted or selected in the QuarkXPress document you're on. If you want to have the glyph after the selection (so rather closing quotes), your code will go like this: set the text of the selection to (the selection & Chevron_fermant). Is it clearer? If not, you can send me a PM in French it might be easier for both of us :-) HTH.

Vincent Nicolas
Posts: 0
Joined: 13 Apr 2011, 09:55

Replace ":" with non-breaking space + ":"

Post by Vincent Nicolas » 05 Sep 2011, 02:22

Oui c'est plus claire... Merci, cependant j'obtiens toujours data utxt00AB au lieu du caractre "
Je suis en QuarkXPress 8.12 MAC OS X 10.5.6

property Chevron_ouvrant : "data utxt00AB" as Unicode text
tell application "QuarkXPress"
activate
set the text of the selection to (Chevron_ouvrant & the selection)
end tell
Merci
Vincent

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

Replace ":" with non-breaking space + ":"

Post by Jean-Marie Schwartz » 05 Sep 2011, 02:32

OK I think I see what it is: put some French quotes before the word data instead of " and after utxt00AB also instead of "
So the code look like this : property Chevron_ouvrant : data utxt00AB as Unicode text
HTH.

Post Reply

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