Skip to main content
Inspiring
November 17, 2008
Question

CS3 Scripting Guide AppleScript

  • November 17, 2008
  • 21 replies
  • 1552 views
Shane Stanley wrote:

> No, I have no financial link with Script Debugger, but I do think that
> trying to script without it is a bit like having one hand tied behind your
> back.
>
> We've talked of doing AppleScript Pro Sessions in Amsterdam, but alas
> nothing has come of it so far. Ray did do a session for Apple over there a
> couple of years back.

Okay, I'll download the Script Debugger demo at some point and give it
a run, but I'd better stick to one thing at a time at this point considering
how long it's taking me just to get through the ID Scripting Guide. I have,
however, managed to get beyond Chapter 2, and have renamed this topic
accordingly.

Thanks,
Roy
This topic has been closed for replies.

21 replies

Inspiring
November 21, 2008
On 21/11/08 2:07 PM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> But hey - it looks like Script Debugger has changed all my Unicode<br />> characters to question marks!<br /><br />The current version isn't Unicode-aware. That should change in the very near<br />future.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
Roy McCoyAuthor
Inspiring
November 21, 2008
Though it works with text if not grep, yeah.

But hey - it looks like Script Debugger has changed all my Unicode
characters to question marks!

Bummer.

I suppose it's Unicode-friendly, and the Edit Menu help has "Special
Characters... Brings up the systemâs Character Palette for entering
Unicode characters." But I don't know what caused this highly unwanted
conversion, or how to avoid it.


Thanks,
Roy McCoy
Inspiring
November 21, 2008
"select text item i of myFoundItems" should be "select item i of<br />myFoundItems" -- a "text item" is a completely different thing.<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
Roy McCoyAuthor
Inspiring
November 21, 2008
Find grep, check, thanks.

I'm now using Script Debugger, and though I went through the PDF carefully I don't know how to take advantage of it.

For example, I tried to do our recent routine below with grep rather than text.

repeat with i from (count of myFoundItems) to 1 by -1
select text item i of myFoundItems
set zoom percentage of layout window 1 to (get zoom percentage of layout window 1)
display dialog "Change this one?" buttons {"Yes", "No", "Cancel"} ¬
default button "Yes"
if button returned of result is "Yes" then
change text item i of myFoundItems
end if
select nothing
end repeat

However, text item i (or what at first appeared to be text item i) was different than following a search with grep rather than text, appearing to contain all the finds. Anyway, I didn't know how to use the SD tools to dig in there and figure out what was going on. I'm a little lost here, but I can still formulate the question: Why doesn't this work with grep as it does with text, and how might I get it to work the same way?

Thanks,
Roy McCoy
Inspiring
November 20, 2008
On 21/11/08 5:06 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> Is there an explanation for this discrepancy, and perhaps a way to avoid it?<br /><br />It looks to me like you've fond a rather nasty bug, and that the results<br />returned from the change are inaccurate if there's a change in the story<br />length.<br /><br />The workaround, if you want an accurate count, is to do a "find grep", and<br />base your count on the result from that.<br /><br />And it looks like the problem is still there in CS4.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
Roy McCoyAuthor
Inspiring
November 20, 2008
I had this, with and without a space preceding "f":

set properties to {find text preferences:{find what:" f P}"}, change text preferences:{change to:" P}"}}
change text document 1
set properties to {find text preferences:{find what:"f P}"}, change text preferences:{change to:"P}"}}
change text document 1

I saw I could do that with GREP in a single command, so I made that:

set properties to {find grep preferences:{find what:" ?f P\\}"}, change grep preferences:{change to:"P}"}}
set myFoundItems to change grep document 1
display dialog ("Found " & (count myFoundItems) & " instances of the search string.")

This works, only when I run it on a test file with this:

f P}
f P}
f P}
f P}
f P}
f P}
f P}
f P}
f P}
f P}
f P}
f P}

the dialog says only 11 instances were found, though there actually are 12 and 12 are changed. Is there an explanation for this discrepancy, and perhaps a way to avoid it?

Thanks,
Roy McCoy
Roy McCoyAuthor
Inspiring
November 18, 2008
Shane Stanley wrote, quoting me:

>> there didn't seem to be a scriptable zoom property that could be
>> set to fit in window.
>
> zoom layout window 1 given fit page -- or fit spread

I put that in my script and saw that it worked, then immediately
commented it out when I kept having to move the dialog window when the
finds got up to under it. Always middle of the screen under the
dialog, yeah.

My question was why I didn't find what I needed on this with all my
searching with the PDF docs and application library. I think I've kind
of answered it myself now, that if I want a command like "zoom", I
should look at the C's in the light blue circles rather than getting
lost in a maze of too-numerous Spotlight finds on my search term.


Thanks,

Roy McCoy
Inspiring
November 18, 2008
On 19/11/08 1:46 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> there didn't seem to be a scriptable zoom property that could be set<br />> to fit in window.<br /><br /> zoom layout window 1 given fit page -- or fit spread<br /><br />> I figure I might be able to get rid of this by<br />> turning off the window display while this adjustment is going on, but<br />> I previously couldn't figure out how to do this.<br /><br />You can't, for what you're after. The best you can do is minimize and<br />maximize the layout window.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
Roy McCoyAuthor
Inspiring
November 18, 2008
Shane Stanley wrote:

> It's a tad more elegant to leave System Events out of it and use
> something
> like this:
>
> set zoom percentage of layout window 1 to (get zoom percentage of
> layout window 1)

I'd say it was quite a bit more elegant, and I would probably never
have figured that out on my own. I'll probably wind up using this line
in all such s&r scripts. I was disconcerted at first by the way the
pages seemed to be jumping all over the place, but this bug became a
feature when I started appreciating that the found instance is always
in the same place at the middle of the screen and is never covered up
by the dialog window, so I don't have to move that or shove the
document window to the side.

I nonetheless wanted to find a way to keep the pages from jumping
around, so I went for that. It again seemed odd that, the same as with
getting the page number of selected text and moving to that page,
there didn't seem to be a scriptable zoom property that could be set
to fit in window. Sending command-0 to System Events didn't seem to
work, oddly, and additionally occasioned some other problem - I lost
my trackpad click, I think. Finally, after a good bit of Googling and
a little delving into the Scripting Guide, I found out how to script a
menu action, so that the page with the found instance now always fits
the window:

set zoom percentage of layout window 1 to (get zoom percentage of
layout window 1)
set myMenuAction to menu action "Fit Page in Window"
invoke myMenuAction

The jumping pages, however, were now replaced by an equally
disconcerting jiggle. I figure I might be able to get rid of this by
turning off the window display while this adjustment is going on, but
I previously couldn't figure out how to do this. I saw how to do it
when opening a new document, but as I recall the command I saw worked
only then and I couldn't find a general alternative. I don't know that
I'd wind up using it here, since as I said I'll likely stick with
having the found instances in the middle of the screen, but hiding the
document window was something I wanted to do before and will likely
want to do again, and so I'd like to know how to do it if it's possible.


Thanks,

Roy McCoy
Inspiring
November 18, 2008
It's a tad more elegant to leave System Events out of it and use something<br />like this:<br /><br /> set zoom percentage of layout window 1 to (get zoom percentage of layout<br />window 1)<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>