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 » 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!

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

Character width

Post by Jean-Marie Schwartz » 29 Mar 2012, 03:35

Great! Congratulations! Just tested it (with icon caution simply) and it rocks! Nice job! :-)
As for the crash, have you tried wrapping the display dialog line in a try block so in case the scripts come accross an issue it gives up (try | display dialog YourDialog | on error | return | end try)? HTH.

mathews
Posts: 0
Joined: 20 Oct 2009, 09:55

Character width

Post by mathews » 29 Mar 2012, 11:08

Hi Jean-Marie,
I gone to my native for summer Holiday. So Sorry for the late reply.
I have tried the script. It doesn't work. My Quark has quit.
Is it works in version 9 ?
If it works in version 9 then why it doesn't work in version 8.
Thanks,
Mathews

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

Character width

Post by Jean-Marie Schwartz » 29 Mar 2012, 21:22

Im sorry it does not work in v8. You know, from one version to another there might be many differences, including scripting capabilities. I guess some information were not accessible in v8 or the dictionary has slightly changed in between. I cannot test the script in v8. Try to check v8 dictionary on the words and verbs that I used and see wether they are available. Sometimes its just a question of syntax and youd have to chnage or add or suppress one word Hard to say. What sytem are you on?

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

Character width

Post by quarkslave » 29 Mar 2012, 21:51

tell application "QuarkXPress9.2"
tell document 1
set total_width to 0
repeat with i from 1 to count of characters [b]of selection
[b]set this_width [b]to (width [b]of character i [b]of selection) [b]as real
[b]set total_width [b]to total_width + this_width
[b]end [b]repeat
[b]return total_width
[b]end [b]tell
[b]end [b]tell


I 'm on Quark8 too, just use this, works fine with my 8.51:


[b]tell application "QuarkXPress"

tell document 1
set total_width to 0
repeat with i from 1 to count of character of selection
set this_width to (width of character i of selection) as real
set total_width to total_width + this_width
end repeat
[b] -- return total_width This made this script not work on 8 for me

display dialog "Your text is " & total_width & " mm wide."

end tell
end tell

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

Character width

Post by Jean-Marie Schwartz » 29 Mar 2012, 22:03

Well its right the return command is not the best one. It just returns the figure but then youre supposed to handle it in one way or another. The display dialog is one way. You could also use the total_width for math or whatever. The code I gave would simply show the total width in the result window of your script editor. Sorry if it was not obvious to you. Thanks Jan for your support!

mathews
Posts: 0
Joined: 20 Oct 2009, 09:55

Character width

Post by mathews » 01 Apr 2012, 06:55

Hi everybodby,
Thanks for helping me.
The following script also quit my quark.
tell application "QuarkXPress"

tell document 1
set total_width to 0
repeat with i from 1 to count of character of selection
set this_width to (width of character i of selection) as real
set total_width to total_width + this_width
end repeat

display dialog "Your text is " & total_width & " mm wide."

end tell
end tell

Hi Jean-Marie I am using Mac OS X - Version 10.6.8
Is anything problem in the OS Version.

Thanks,
Mathews

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

Character width

Post by Jean-Marie Schwartz » 01 Apr 2012, 09:15

OK, I can see 1 thing: the variable total_width is actually a real number so cannot be displayed as such; you must coerce it to string I think. So please try adding a line: "set total_width to total_width as string" before the line "display dialog" (with no quotes!). And let me know. I'm sorry but as I said I stopped my tests at the Script editor level so the result in my first code was readable in there. I didn't realized it was a step too short.

mathews
Posts: 0
Joined: 20 Oct 2009, 09:55

Character width

Post by mathews » 01 Apr 2012, 12:31

Hi Jean-Marie,
Still my Quark Quitted after editing the script as follows:
tell application "QuarkXPress"

tell document 1
set total_width to 0
repeat with i from 1 to count of character of selection
set this_width to (width of character i of selection) as real
set total_width to total_width + this_width
end repeat
-- return total_width This made this script not work on 8 for me
set total_width to total_width as string
display dialog "Your text is " & total_width & " mm wide."

end tell
end tell
Is anything wrong in my Script Editor?
I am having
AppleScript Editor
Version 2.3 (118)
AppleScript 2.1.2

Thanks,
Rakesh

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

Character width

Post by Jean-Marie Schwartz » 01 Apr 2012, 21:45

Then I don't know. I have the same config as you but Quark (I'm on v9). And it works great here! I cannot test on v8 so if someone else could it would be great for you. Sorry.

Post Reply

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