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 » 05 Sep 2011, 02:58

BINGO!!! it was the quote. Now it works great... Now I can start something.
Merci beaucoup every body.
Vincent

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

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

Post by Vincent Nicolas » 05 Sep 2011, 03:59

Encore une petite aide... j'aimerai parcours caractre par caractre tous les caractres d'un bloc texte slctionn.
J'avais dans l'ide de faire un truc du style (ci-dessous) mais comme je vais rajouter des caractres, comme aprs un guillemet (171), je rajoute un caractre inscable (15), ma slction ne serai plus jour.
get number of character of the selection
de faire un boucle avec un variable i qui incrment jusqu' number of character
get the unicode value of character i of the selection

et de traiter caractre par caractre, si le caractre est
":" rajouter un espace inscable devant
";" rajouter un espace inscable devant
""" ancien guillemet, mettre le guillemet ouvrant
""" ancien guillemet, mettre le guillemet fermant
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, 04:56

Please keep in mind this forum is in English only. Though you can use French if you contact me through private message.
Then to get every single character of a text box is not the best way to deal with text. Much simpler and probably much faster is to set every text where it is ":" to (Espace_insecable & ":") note that these quotes are English ones since it is aimed to quote text in AS this line wrapped in a tell text box block. If you search the forum for "search, replace" you'll find some examples of scripts that do the search and replace in different ways

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

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

Post by Vincent Nicolas » 05 Sep 2011, 20:40

Hello,
get number of character of the selection
Return the nomber of character is selected.
What would be the other way to selection a text from 1 to 5. I have been playing with it but can't figure it out the right syntax.

By the way, do you have any reference to suggest for learning Quark Scripting (not the Quark PDF) ?
Thanks
Vincent

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

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

Post by Jean-Marie Schwartz » 08 Sep 2011, 05:40

Sorry! I was off the last 2 days.
I don't really understand your question. What are trying to do exactly? What is your aim? Sometimes coding a script may take a totally different way from what you'd do "manually".

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

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

Post by Vincent Nicolas » 08 Sep 2011, 20:55

Hello,
I would like to scan the selected text by character and apply some rules to modify the selected text.
Rules like:
- Double/triple spaces -> allow only one space
- double point ":" -> if not, place a insecable space before it
- Apostrophe -> place the right one
- Guillemet " -> place chevron_ouvrant
- Guillemet " -> place chevron_fermet
- some others rules
I can delete a character in the selection, the selection is keeped. But if I add a insecable space before a character, the selection is gone, so the script stop.
This function cancel my selection:
set before character i of the selection to Insecable -- cette fonction dselect le texte
Thanks for your help
Vincent

property Chevron_ouvrant : data utxt00AB as Unicode text
property Chevron_fermant : data utxt00BB as Unicode text
property Guillement : data utxt0022 as Unicode text
property Apostrophe_simple : data utxt0027 as Unicode text
property Apostrophe : data utxt2018 as Unicode text
property Interrogation : data utxt003F as Unicode text
property Exclamation : data utxt0021 as Unicode text
property Double_Point : data utxt003A as Unicode text
property Point_Virgule : data utxt003B as Unicode text
property Insecable : data utxt000F as Unicode text

property i : 1 as integer

tell application "QuarkXPress"
activate

set LengthSelect to number of character of the selection

repeat until i > LengthSelect

set CurrentCharacter to the character i of the selection

if CurrentCharacter = " " then

set PreviousCharacter to the character (i - 1) of the selection

if PreviousCharacter = " " then
delete character i of the selection
set LengthSelect to LengthSelect - 1
else
set i to i + 1 -- on passe au suivant

end if

else if CurrentCharacter = ":" then

set PreviousCharacter to the character (i - 1) of the selection

if PreviousCharacter = " " then
set the character (i - 1) of the selection to Insecable
set i to i + 1
else if PreviousCharacter = Insecable then
set i to i + 1
else
set before character i of the selection to Insecable -- cette fonction dselect le texte
set LengthSelect to LengthSelect + 1
set the selection of the text 1 to 10
set i to i + 2
end if
else
set i to i + 1 -- on passe au caractre suivant
end if

end repeat
end tell

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

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

Post by Jean-Marie Schwartz » 08 Sep 2011, 21:43

As for the French quotes, this can be automated at importing the text: set Quark's prefs to Application > Paramtres de saisie > Guillemets, format and Guillemets typo. Then at importing text, tick the Convertir les guillemets checkbox. As for scanning the text of the selection, I would first copy the text of the selection to a variable or a list of characters (then you'd have to check every single character as an item of the list) and only after having replaced everything copy back to the selection. Are you with me? Now, in the list of characters, keep in mind as soon as you add a space or whatever, the number of the characters is modified so say character 3 becomes character 4 and so on A trick is to take the list in reverse, from last to first. This said, you'll find some very helpful scripts in this forum that do perform Search and Replace. They probably don't work on a selection but throughout an entire document or story of text. It really depends on what you wish to perform. So again, what is your aim? What is the general context of your script? Do you wish to work only on selected text? Or do you wish to make tons of changes "at once" throughout a 1000+-page document? The approach shall be totally different in one case or another.
As for documentation about AppleScripts, in French, you can read this: Prsentation d'AppleScript.You can also dig into this current forum and search for code, then try to understand how they work and how they've been coded. Scripting_Ace's forum is also a very good place for learning AppleScript (in English).
Some more info here.

gminder
Posts: 0
Joined: 10 Jul 2012, 13:20

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

Post by gminder » 10 Jul 2012, 08:31

Hi,I saw your post while dealing with some invisible character issues. However I have a question that is related to the Unicode topic.I've made an AppleScript that puts XML tags around a story. It work quiet well and is cheaper that some extensions ;-)The only issue I have is that I would like the script to create a text file UTF-8 encoded (for now I can workaround by copy/pasting the content in a text editor). I've been googling a lot in the past days but have the feeling that AppleScript is not supporting Unicode very well. Could you confirm my feeling? Do you have any good advice?Thanks in advance, Guy

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

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

Post by Jean-Marie Schwartz » 11 Jul 2012, 22:11

Well! Both Quark and AppleScript do support Unicode. AppleScript only deals with UTF-16 by default. I don't know where the tags come from (if you created them directly in AS or if you get a text file from outside). So if pure AS, you should rather use UTF-16 encoding in the XML header. If you get the text from outside, maybe you should first convert UTF-8 to UTF-16 via a shell script. Does it make sense?

gminder
Posts: 0
Joined: 10 Jul 2012, 13:20

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

Post by gminder » 12 Jul 2012, 21:31

Thanks for your reply.Basically, what I'm doing is that I place the in the text box itself; the tagging is based on the defined style an it works fine. The only thing that I didn't work out is how to output a text file encoded in UTF-8. I can create a text file, but the encoding doesn't seem to be right.Is there an AppleScript command that says, " set myText as Unicode UTF-8"? Probably too easy no? ;-)Have a nice week-end, Guy

Post Reply

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