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

Roy McCoyAuthor
Inspiring
December 8, 2008
Eric,

Could you please send me a script containing the getParentPage function you posted on Nov. 21? I didn't quite get it but I think I might if I saw it in the context in which it was used.

Thanks,

Roy McCoy
roymccoy dot nl at gmail dot com
Roy McCoyAuthor
Inspiring
November 27, 2008
Shane Stanley wrote:

> BOMs tend to matter only when you're moving stuff between systems
> using
> different endian processors, eg Intel vs PPC. It's a pity in a way
> that BOMs
> aren't used more widely, but much of the industry seems stuck in
> good-enough
> mode with ASCII variants. if you're not seeing text get garbled,
> you're
> fine.

I did get some garbled text the other day, but I don't think it was a
BOM issue. Setting the TextWrangler encoding preferences for Little-
Endian seems to occasion some problems, mainly undesired alerts, so I
changed them back to Western (Mac OS Roman). As far as I can remember,
I needed Little-Endian only for doing something with ID tagged text
that I'm now done with for the time being.

Hey, here's one I managed to do on my own:

*****

tell application "Adobe InDesign CS4"
activate
set myDocument to make document
set myMarginPreferences to margin preferences of myDocument
set bottomMargin to bottom of myMarginPreferences
set bottomYPoint to (page height of document preferences of
myDocument) - bottomMargin
set rightMargin to right of myMarginPreferences
set rightXPoint to (page width of document preferences of myDocument)
- rightMargin
tell page 1 of myDocument
set myTextFrame to make text frame with properties {geometric bounds:
{top of myMarginPreferences, left of myMarginPreferences,
bottomYPoint, rightXPoint}}
select insertion point -1 of myTextFrame
end tell
end tell

*****

I suppose that's what you'd call trivial, but I didn't have it before
and now I do - assigned to cmd-n, understandably.

It wasn't easy for me and I blew too much time on it. I think the main
problem was that I kept hitting this point:

tell application "Adobe InDesign CS4"
activate
set myDocument to make document
set myMarginPreferences to margin preferences of myDocument
tell page 1 of myDocument
set myTextFrame to make text frame with properties {geometric bounds:
{top of myMarginPreferences, left of myMarginPreferences, (page height
of document preferences of myDocument) - (bottom of
myMarginPreferences), [...]}}

at which it would keep telling me:

Canât make «class marb» of «class impp» of document "Untitled-
" of application "Adobe InDesign CS4" into type number.

I couldn't figure out what was going on there, and still can't. There
wasn't any problem with top of myMarginPreferences. bottom of
myMarginPreferences had to be a number, in order to work with top of
myMarginPreferences which evidently was text, and, uh... confused again!

Oh... top of myMarginPreferences is text, while
page height of document preferences of myDocument is a number, right?
If so, that doesn't seem to be intuitively evident, exactly.


Thanks,

Roy
Inspiring
November 27, 2008
On 28/11/08 6:11 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> Another question I'm having is whether there's an important<br />> difference as far as TextWrangler and AppleScripting for InDesign are<br />> concerned, between "UTF-16 Little-Endian" and "UTF-16 Little-Endian,<br />> no BOM". I have to use Little-Endian, something told me, but sometimes<br />> I don't have a choice between the two variants. I can see at<br />> http://en.wikipedia.org/wiki/Byte_Order_Mark<br />> what "BOM" means, but not whether it matters for me and whether I<br />> want to avoid it or not.<br /><br />BOMs tend to matter only when you're moving stuff between systems using<br />different endian processors, eg Intel vs PPC. It's a pity in a way that BOMs<br />aren't used more widely, but much of the industry seems stuck in good-enough<br />mode with ASCII variants. if you're not seeing text get garbled, you're<br />fine.<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 27, 2008
On Nov 21, 2008, at 10:33 PM, Shane Stanley wrote:

> You're being paranoid.

Glad to hear it, thanks. At the moment:

(1) Couldn't get this to work:

set properties to {find text preferences:{find what:"a{'"}, change
text preferences:{change to:"á"}}
change text document 1
set properties to {find text preferences:{find what:"A{'"}, change
text preferences:{change to:"Ã"}}
change text document 1
set properties to {find text preferences:{find what:"a{`"}, change
text preferences:{change to:"à"}}
change text document 1
set properties to {find text preferences:{find what:"A{`"}, change
text preferences:{change to:"Ã"}}
change text document 1

It apparently kept changing a{` to acute á rather than the desired
grave à - damnedest thing! I finally figured out that it actually
wasn't changing a{` to á, but was catching it along with a{' so that
it was already changed when the search for a{` occurred.

I switched the order of the replaces - also at e/E, i/I, o/O and u/U -
and the script now works. But it seems kind of dangerous. I don't
suppose there's anyway to fix something so that there's no chance this
could happen again, is there?

(2) Another question I'm having is whether there's an important
difference as far as TextWrangler and AppleScripting for InDesign are
concerned, between "UTF-16 Little-Endian" and "UTF-16 Little-Endian,
no BOM". I have to use Little-Endian, something told me, but sometimes
I don't have a choice between the two variants. I can see at http://en.wikipedia.org/wiki/Byte_Order_Mark
what "BOM" means, but not whether it matters for me and whether I
want to avoid it or not.


Thanks,

Roy
Roy McCoyAuthor
Inspiring
November 23, 2008
> It looks to me like you've fond a rather nasty bug, and that the
> results
> returned from the change are inaccurate if there's a change in the
> story
> length.
>
> The workaround, if you want an accurate count, is to do a "find grep",
> and base your count on the result from that.
>
> And it looks like the problem is still there in CS4.

I've now installed and started using CS4 myself, and have noticed
some problems, both scripting and not, that are likely not new. Not
scripting, InDesign will say it made a replacement when it couldn't
have, because the search text can't be found. Scripting, I don't seem
to be able to search for a ^p paragraph ending at the end of a search
string.

Being now on CS4, and having read of an available CS4 Scripting Guide,
I guess I'm set for yet another subject-line change and another round
of Scripting Guide procrastination. Seems to kind of justify the
previous
procrastination, that's pleasant.


Thanks,
Roy McCoy
Inspiring
November 21, 2008
On 22/11/08 12:48 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> Do I detect the slightest bit of sarcasm there,<br />> or am I just being paranoid? :-)<br /><br />You're being paranoid. There are two ways to apply styles: using the<br />command, or setting the applied paragraph style property. The command gives<br />you control over overrides.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
November 21, 2008
Generally I just snag properties directly from a selection, or at least use it as a clue for directions to look in the script dictionary.

I start out with "get properties of selection", then start refining. Like, for example to figure out how to get the page number that an inline graphic occurs in:

get properties of selection turns into
get parent text frames of selection turns into
get parent of item 1 of parent text frames of selection

which eventually turned into this function (after hitting my first grouped text box, lol):

on getParentPage(thisObject)

tell application "Adobe InDesign CS2"
if class of thisObject = page then
return thisObject
else
return my getParentPage(parent of thisObject)
end if
end tell
end getParentPage


which I call with getParentPage(item 1 of parent text frames of thisInlineGraphic)
Roy McCoyAuthor
Inspiring
November 21, 2008
> Try using the apply paragraph style command.

Do I detect the slightest bit of sarcasm there,
or am I just being paranoid? :-)

Seriously, I think I'll be able to dig out the commands
okay, but it's harder to figure out why it says it can't
get something I think it should be able to get just fine,
or why it can't display an apparently textual value as
text, etc.

> Also, when you get a bit of time fire up Script Debugger,
> open ID's dictionary, and click on Explorer.
> Lots of useful stuff...

Dictionary, Explorer, yeah. Interesting that I can still
use Script Debugger for some functions - at least for the
next 17 or 18 days. After that I'll probably be waiting a
long time for the dictionaries again (though if I get all
those old, no-longer-working Classic applications off my new
computer, that will help) and loping from suite to suite again,
but happily the blue circles are at the top.


Thanks,
Roy McCoy
Inspiring
November 21, 2008
Try using the apply paragraph style command. Also, when you get a bit of<br />time fire up Script Debugger, open ID's dictionary, and click on Explorer.<br />Lots of useful stuff...<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
Yagh! Looks like I'm immediately back to Script Editor then. It's
okay, I missed its nice green and red buttons anyway.

Problems problems problems. I'm dealing with three paragraph styles at
this point. The text is originally all in [Basic Paragraph]. I managed
to apply two of the three styles to their respective text okay, using
TeX codes deleted at the same time, but then I couldn't change [Basic
Paragraph] to the third style. I finally got it to select both [Basic
Paragraph] and one of the other two styles (why it did that I didn't
know, I only put the one), but then it looked like it wasn't going to
work anyway, as InDesign apparently doesn't like to look for nothing.

So I went back and started with:

set applied paragraph style of every paragraph of parent story of
selection to paragraph style "dr" of document 1

So the styles are now all applied okay. But I'm curious about an
apparent problem with [Basic Paragraph], and about how to do a
universal change from one style to another generally, seeing as how I
did it with the help of the TeX codes this time.

I've made considerable progress today (my sixtieth birthday) and am
very encouraged. I can get retrieve my Unicode things from backup
files tomorrow. Many thanks again for your invaluable help. If you
feel like putting me somewhere where other Applescripters are
pitching, just tell me where to go.


Roy McCoy