Hello. I’m new to AppleScript, trying to get my head around its syntax. I’m reading several tutorials online as well as watching a few videos (Ben Waldie has quite a few). With the help of these tutorials I have found the dictionaries and slowly becoming familiar with the properties, classes, etc.
However, there seem to be other words/phrases that are in scripts such as “at end of”. Is there a list of such phrases anywhere? How do scripters know where to place these phrases?
Thanks.
Model: iMac
AppleScript: 2.0.1
Browser: Safari 533.19.4
Operating System: Mac OS X (10.5)
Hi, welcome to the forum. There are a lot of good books out there on the subject. I found The Tao of Applescript invaluable in developing a working understanding of Applescript; it’s somewhat dated, but provides a great introduction to syntax, flow control, lists and many other conventions. It’s also cheap as dirt.
]http://www.amazon.com/Applescript-Disks-Bmugs-Macintosh-Scripting/dp/1568301154
Thanks for the suggestion, Marc. I ordered the book (cheap as dirt is almost an understatement).
Anyone else have other suggestions for learning the basics of AppleScript syntax?
Practice, practice, practice.
Seriously, explore it. Write, fail, read, write, fail, read, write. success.
And most of all. have fun with it. Cheers!
Jim
BLUEFROG
Thanks, Fistoprince. I do have that URL marked. It is very valuable - however, there is so much information there. As a beginner, I’m trying to get my head around the syntax. As I mentioned in my example above, it is not clear to me where I can find a list of phrases such as “at end of” and how to use them.
I am gathering, from my research, that the phrase “at end of” is really three separate keywords (see http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_keywords.html%23//apple_ref/doc/uid/TP40000983-CH222-SW1).
I just ordered Learn AppleScript: A Comprehensive Guide… (http://www.amazon.com/Learn-AppleScript-Comprehensive-Scripting-Automation/dp/1430223618/ref=sr_1_2?s=books&ie=UTF8&qid=1297694366&sr=1-2). This seems to be the latest book on the topic, so, hopefully, as I continue on, things like how/when to use “at end of” will become more clear.
Thanks.
set input to {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
set output to items 1 thru 3 of input
display dialog (output) as string
set output to items 3 thru -1 of input
display dialog (output) as string
set output to items -3 thru -1 of input
display dialog (output) as string
set output to items 3 thru -3 of input
display dialog (output) as string
Here is a nice example of how to go through a list backwards.
Notice that item -1 is the last item, -2 the second last and so on while items 1 and 2 are as normal the first and second.
I tend to find that I learn languages best through playing around with them.
AppleScript is designed to look like English to make scripts easier to understand, but an English-like phrase doesn’t necessarily imply an English-like logic. A partial phrase like “at end of” doesn’t have any meaning at all in AppleScript. You’ll usually it in an application command such as:
tell application "Blah"
make new document at end of documents with properties {name:"Fred"}
end tell
Here, ‘make’ is an application command (not a core AppleScript language command) which has been included in the scripting implementation of the application “Blah”. It has three “labelled parameters”: ‘new’, ‘at’, and ‘with properties’ whose values are respectively the class of the item to be created (‘document’), a reference indicating the location at which to insert the item (‘end of documents’), and a record containing initial properties for the item.
So “at end of” is 'make’s parameter label ‘at’ followed by part of the reference ‘end of documents’. It doesn’t have any meaning or function in its own right and you won’t find it in a list of phrases you can look up.
When you come across an interesting “phrase” in AppleScript, you need to find out why it contains the words it does. That’ll make how to use it more obvious.