Character width

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 23 Mar 2012, 03:14

Sorry i'm late answering, but getting involved with scripting isnt my primary task here, but no one does or can instead, so when I have some time on my hands, the script grows.
But I was a littlesuccesful in completing. But because I dont have the Debugger like you and Safari doesnt work since our IT messed up some proxy-stuff, i cant post the code formatted. Instead i'll post snippets to discuss. There isnt much to do, its brilliant by now, but can be less risky.
I fixed the Line/Page thing by accident
make line box at before current box with properties {start point:
tried to change "at beginning" (thinking it would be page 1 always) to current box and discoverd somewhere the AS-thing "before", tried it, bingo = line is where the action is :-)
Had problems finding the lines when I marked 2+ lines
set CharsInLine1ofSelection to count of character of line 1 of selection
didnt work, so I counted the chars until the baseline of character changes from char i to char i+1.
Now if more textline than one is marked (e.g. by accident, we dont need to cross a line over two lines)then chars will be counted and crossed out to the end of line1 of the selection.
Used your snippet (big thx angain!) to keep the value between 0 and 100
but found out better to use

quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 23 Mar 2012, 03:20

Now lets please look into some little details left:
set Check to "0"
repeat while Check is "0"
set MYcyan to text returned of (display dialog "Strichfarbe wird angelegt: (01001000)" & return & "Neue Farbe: " & return & "CYAN =" default answer {"0"} buttons {"Weiter"} default button 1) as integer
if (0 (MYcyan as integer)) and ((MYcyan as integer) 100) then
set Check to "1"
end if
end repeat

Is working fine. But entering everything but numbers e.g. "asd" results in canceling/stopping the script after that.
I know from turbopascale a function to convert string-values into numbers (of their codepage), so an "A" resulted in 65.
Anything would be better than an exit, so I need a way to convert any string-entry to an number or if a string is entered and AS could check that easyler, then I repeat the dialog.

quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 23 Mar 2012, 03:27

I stumbled upon another big flaw to kink out if possible:
Is there a way to prevent the script from makeing any actions done before accessible by Apple+Z anymore? Only what I have done is drawn a single line

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

Character width

Post by Jean-Marie Schwartz » 23 Mar 2012, 04:51

quarkslave wrote:found out better to use

Oh sure! Never mind! I must say I didnt really think about coding it like a pro. BTW, you should add a checker for ensuring values typed in the dialog field are not letters. The checker so far will transform the text returned into integer, but if ever it is letters instead of numbers, it will just fail. So wrap your checker in a try block with a on error statement simply repeating the dialog as if it were wrong numbers. Are you with me?
Glad its getting closer to your expectations! And thanks for the before thing I wasnt aware of. I shall play with that later on and see how it works!

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

Character width

Post by Jean-Marie Schwartz » 23 Mar 2012, 04:53

quarkslave wrote:Now lets please look into some little details left
Oops! sorry again! I answered that question in my previous post actually. Les grands esprits se rencontrent as we say in French :-)

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

Character width

Post by Jean-Marie Schwartz » 23 Mar 2012, 04:56

quarkslave wrote:I stumbled upon another big flaw to kink out if possible:
Is there a way to prevent the script from makeing any actions done before accessible by Apple+Z anymore? Only what I have done is drawn a single line
Im sorry, this is not clear enough to me. Are you asking wether it is possible to Apple-Z sth done through a AppleScript? If so, no its not possible unfortunately. To what I know. If your question is different please put it in other words so I get what you mean.

quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 23 Mar 2012, 05:02

Jean-Marie Schwartz wrote:
Im sorry, this is not clear enough to me. Are you asking wether it is possible to Apple-Z sth done through a AppleScript? If so, no its not possible unfortunately. To what I know. If your question is different please put it in other words so I get what you mean.

I've done some changes in my doc. Now I use my script. After that, I cant use Apple+Z anymore and all my undo-able changes are gone. And I only drawed 1 line.

My concern is this: My collegues do some stuff, knowing 30 back-steps are possible, then they start the script to draw the line, and after that they notice that all possible back-steps are gone.

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

Character width

Post by Jean-Marie Schwartz » 23 Mar 2012, 05:17

Yes I know its a big and real problem indeed! Even the line itself cant be undone. (Well thats a big deal as for a line, but when I work on text and I cannot undo the changes, its annoying! So as far as Im concerned I always save my job first and revert back to saved if needed. But its clear you cannot undo 30 actions that way!)

quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 29 Mar 2012, 02:57

-- Fritz streicht durch-Script --
-- --
-- von Jan Krause, 2012 --
-- with help from J.-M.-Schwartz --

tell application "QuarkXPress"

tell document 1

set myX1 to 0
set myY1 to 0
set myX2 to 0
set myY2 to 0

set MaxLines to 0
set MaxChars to 0
set MaxCharsLineOne to 0

(* How many Chars/Lines? *)
set MaxLines to count of lines of selection
set MaxChars to count of character of selection

-- display dialog "MaxLines: " & MaxLines & return & "MaxChars: " & MaxChars & return & "MaxCharsLineOne: " & MaxCharsLineOne

(* Chars in Line 1 of Selection *)
if (MaxLines > 1) then
set Temp1 to 0 as real
set Temp2 to 0 as real
set halt to false
set y to 0

repeat with y from 1 to (MaxChars - 1)
set Temp1 to (baseline of character y of selection) as real
set Temp2 to (baseline of character (y + 1) of selection) as real
-- display dialog "Char " & y & "Baseline: " & Temp1 & return & "Char " & (y + 1) & "Baseline: " & Temp2
if (halt = false) then
if (Temp2 > Temp1) then
set MaxCharsLineOne to y
set halt to true
else
set MaxCharsLineOne to (y + 1)
end if
end if
end repeat
end if

-- display dialog "MaxLines: " & MaxLines & return & "MaxChars: " & MaxChars & return & "MaxCharsLineOne: " & MaxCharsLineOne

(* Y1=LOWER LEFT *)
set MyPageOffset to (top of bounds of current box as real)
set myY1 to (baseline of character 1 of selection) as real
set myY1 to (MyPageOffset + myY1)

(* Y2=TOP RIGHT *)
set MyPageOffset to (top of bounds of current box as real)
set myY2 to (baseline of character 1 of selection) as real
set myY2 to (MyPageOffset + myY2)
set TEMPvar to (size of character 1 of selection) as real
set TEMPvar to (((TEMPvar * 0.35275) / 100) * 70)
set myY2 to myY2 - TEMPvar

(* X1 LEFT *)
set MyPageOffset to (left of bounds of current box as real)
set myX1 to (horizontal offset of character 1 of selection) as real
set myX1 to (myX1 + MyPageOffset)

(* X2 RIGHT *)
set MyPageOffset to (left of bounds of current box as real)
set total_width to 0

if (MaxLines = 1) then
repeat with i from 1 to MaxChars
set this_width to (width of character i of selection) as real
set total_width to (total_width + this_width)
end repeat
set myX2 to (myX1 + total_width)
end if

if (MaxLines > 1) then
repeat with i from 1 to MaxCharsLineOne
set this_width to (width of character i of selection) as real
set total_width to (total_width + this_width)
end repeat
set myX2 to (myX1 + total_width)
end if

(* CHECK/CREATE LINECOLOR *)
if not (exists (color spec ("Linienfarbe Script"))) then

set Checker to "0"
set Switcher to "0"
repeat while Switcher is "0"
set Farben to {"000-100-100-000 Rot", "000-000-000-100 Schwarz", "000-000-000-000 Wei", "000-100-000-000 Magenta", "100-000-000-000 Cyan"}
choose from list Farben with prompt "Welche Strichfarbe wird gewnscht?" with title "Scriptfarbe initialisieren" OK button name "Klaro " cancel button name "Abbruch " default items "000-100-100-000 Rot" without multiple selections allowed

if the result is not false then
set Checker to item 1 of the result
set Switcher to "1"

if (Checker = "000-100-100-000 Rot") then
make color spec at beginning with properties {name:"Linienfarbe Script", CMYK color value:{0 * 655.35, 100 * 655.35, 100 * 655.35, 0 * 655.35}, separation:true}
end if
if (Checker = "000-000-000-100 Schwarz") then
make color spec at beginning with properties {name:"Linienfarbe Script", CMYK color value:{0 * 655.35, 0 * 655.35, 0 * 655.35, 100 * 655.35}, separation:true}
end if
if (Checker = "000-000-000-000 Wei") then make color spec at beginning with properties {name:"Linienfarbe Script", CMYK color value:{0 * 655.35, 0 * 655.35, 0 * 655.35, 0 * 655.35}, separation:true} end if if (Checker = "000-100-000-000 Magenta") then make color spec at beginning with properties {name:"Linienfarbe Script", CMYK color value:{0 * 655.35, 100 * 655.35, 0 * 655.35, 0 * 655.35}, separation:true} end if if (Checker = "100-000-000-000 Cyan") then make color spec at beginning with properties {name:"Linienfarbe Script", CMYK color value:{100 * 655.35, 0 * 655.35, 0 * 655.35, 0 * 655.35}, separation:true} end if else display dialog "Linienfarbe Script" & return & "muss aber angelegt werden." with icon alias ((path to me) & "Contents:Resources:streich.icns" as string) buttons {"Hmpf"} default button 1 giving up after 3 end if end repeat end if (* DO THE LINE *) make line box at before current box with properties {start point: {(myY1 as string) & " mm", (myX1 as string) & " mm"}, end point:{(myY2 as string) & " mm", (myX2 as string) & " mm"}, color:"Linienfarbe Script", shade:"100%", width:1, style:solid line, end caps:plain line} end tellend tell

quarkslave
Posts: 95
Joined: 19 Sep 2008, 04:05

Character width

Post by quarkslave » 29 Mar 2012, 03:13

Phew, I'm satisfied with my coding/script/work. Again, many thanks to you Jean.
I've posted the final Script, but it wont run completely at your mac, becausewell:
with icon alias ((path to me) & "Contents:Resources:streich.icns" as string)
I found out that Quark didnt care to execute the script, even if I saved it as a programm (.app). Now I could edit the content and add the streich.icns in the reccources folder. Then it works. I wanted to give the script a touch, so I wanted to use another icon than stop/caution/note.
So if you want to execute, save as app, add a/your iconfile (and change the code to the name of your file or name it: streich.icns) and your good.
I've changed the dialogs for the color-question to "choose from list"-sytle, as i found out about it. I thought someone could easyly change the color afterwards, and that a few choices can do.

What is strange, but i havent checked on other machines but you said it too: If I close a dialog by the red X (if I'm quick enough, gave it giving up after 3) then in 80% Quark Crashes, with: ((Version: 8.5.1.0 (8.5.1.0) OS Version: Mac OS X 10.6.8 (10K549), Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000)) But i cant make something out of these crash-reports.
Now Ill provide it to my collegues and I hope, someone will use it, dammit :-)
Hope noone will use the red X, otherwise its done!

Post Reply

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