I’m new to AppleScript (but not new to scripting). I’m finding it hard to work out how to write the syntax and how to us the dictionary’s.
I wanted to make a new script for InDesign for a first off script. I was looking to activate InDesign and create a new document with specific height and width. So using the dictionary I try to work out how to make a new document. Only thing that I can find that comes close is the “make” Command
So from this I gather that I use the “Make” command followed by “New” and then the type class (which I would assume is a “Document”).
So to break this down I’m using the Command “Make” with “New” which I guess would be considered like a built in modifier for the “Make” command… and doing this with the “Document” class makes an instance of this particular class.
I hope this is right so far… please tell me if I’m not. because I already have questions…
Is there a way to us the dictionary to find out what classes the “Make New” command can work with… because its obviously not going to work with the “Application” class. Or can you do it the other way around… Look at the Class in the dictionary and find out what commands are compatible with it? Also I tried doing the script without “New” and it worked just fine… Does that mean that the modifiers listed for the make command above (new, at, with data, with properties) are unnecessary?
Ok so next I want to be able to also set dimensions of the document as I create it… So so far I have:
tell application "Adobe InDesign CS3"
make new document
So Im looking at the Make command still and the next modifier is the “At” reference which I assume is I can skip over and it will just put it in its default location. The next 2 modifiers seem like they could be related however… “With Data” sounds right… but then again “With Properties” sounds right too! Lets go with the “With Properties” modifier. Now I guess I should be looking for a “Page Width” and “Page Height” property under the document class. But I cant find anything… the only thing I can find is a “Document Preferences” property and I found out that there is also a Class called “Document Preferences” as well. So am I right in saying that this is a Property that is also a Class? Lets say it is… I then look at the “Document Properties” Class and see that it has “Page Width” and “Page Height” properties. So lets try and work this into the code:
tell application "Adobe InDesign CS3"
make new document with properties document preferences with page width "100mm" and page height "100mm"
end tell
Well that SOOOOO didn’t work. Can anybody please read through my logic and please explain to me where I’m getting it wrong.
Thanks
Check out page 13 of the PDF “InDesign CS3 Scripting Guide AS.pdf” that comes with ID CS3.
Also check out the simple Document Object Model i[/i] on page 15 of the PDF “InDesign CS3 Scripting Tutorial.pdf”. Understanding the object model is key to writing functioning scripts (Ok, Luck sometimes plays a part too! :P)
Your logic makes sense but your syntax is off.
- You [i]make[/i] a document [i]then change its dimensions[/i]. (page 13)
- This one is a bit harder to explain. You have to Tell the Preferences of the Document what to do! (Note: There are Document Preferences of the Application but this will change your Default Page Settings (So every document would start with these dimensions, etc.) When you have Parent Properties with Child Properties you need to address the parent to change the child (ain’t that the truth! :lol:) If you have a solitary property, like the file path, you would be talking to the document (You don’t want the file path of the app, right ?!) But if I want to change the Rule Gap Tint of the Footnote Options (also a Parent Property with its own children) then I need to address the Footnote Options on behalf the Child Property I want to change. Is this making any sense? I hope so.
Long Story, still long. (read the comments)
tell application "Adobe InDesign CS3" -- Talking to the App
make new document at beginning -- Make a new document at the front.
tell document 1 -- Talking to the Document
tell view preferences -- Here's another Parent Property with Child Properties I want to change! Talking to the Prefs of the Document
set vertical measurement units to inches
set horizontal measurement units to inches
end tell -- Done talking to the Prefs
tell document preferences -- Talking to more Prefs of the Document
set page height to 8
end tell -- Done talking to the Prefs
end tell -- Done talking to the Document
end tell -- Done talking to the App
. Note this code is very basic. No attempt at optimizing for brevity or any other tricks have been shown. (All in good time!)
Don’t despair in your studies. InDesign is one of the harder progs to script (due to its very full and deep Dictionary). One note: Get in the habit of using the “Location” property of the make command. Some quirky things REQUIRE it to function properly but will run without it! Valid options: at beginning, at end, before/after (some object)
Have Fun With It!
Jim Neumann
BLUEFROG
Thank you very much for your input. I think I understand everything you said… but just to clarify… for all objects you must create it first before you can set its properties. So say I was drawing a square on the page I would have to create the object first and then set its size?
Thanks!
Actually, no. With InDesign it is a requirement when making a Document but not necessarily other items.
That’s the labourious part about scripting. learning peculiarities of an App’s language. (In Illustrator you can create a document at a given size but then you can’t change it afterwards!!! :mad:) I tend to think of them as dialects. InDesign may have a text frame while Quark has a text box. Same concept. you just need to know the differences in language. Fortunately the programming basics apply: how and when to use handlers, conditionals, etc.
-Jim
geez… how crazy. Oh well I guess the only way to work these out is to try and ask questions.
Thanks for that!