AppleScript Dictionary Explained in Plain English

Ranked #4,189 in Computers & Electronics, #77,538 overall

How to Understand those vague Descriptions found in AppleScript Dictionaries

Ever gone to look at an AppleScript Dictionary in Script Editor and tried to implement the various elements only to find that no matter how many variations you try, you still end up with error dialogs, most of which aren't very helpful?

This site will show you dictionary entries with 1 or 2 snippets of example code  to get you started. Some other AppleScripts can be found at: http://www.squidoo.com/applescript and for AppleScripts that are more advanced, see: http://www.squidoo.com/advanced-applescript-code

Blue Pastel Designed on Macintosh

Tips on Reading and Understanding AppleScript Dictionaries

Before you Get Started, I Highly Recommend that you Take a Quick Look at these Comments on Dictionaries

Apple-AppleScript-Image-EventsAn entry taken from the AppleWorks 6 Dictionary:

make v : Make a new element
make
new type : the class of the new element.
at location specifier : the location at which to insert the element
[with data any] : the initial data for the element
[with properties record] : the initial values for the properties of the element
--> specifier : to the new object(s)

Some things to note about dictionary entries

1) The first line, make v : Make a new element, is the basic definition of the term

2) The second item in the first line in italics (v here) describes the term as an English part of speech, here, a verb. This is significant, because AppleScript is written basically like sentences in English.

3) Text in bold is to be written literally

4) All plain text is not to be taken literally and is a description of the element or term in bold.

5) Text within straight brackets are optional parameters that may not apply for what you want to do.

6) Blue, underlined text is a link to a further definition of the term or attribute.

In the 'make' example above (omitting optional stuff), you could say:

make new document at desktop


If you have any questions or comments please go to my Guestbook Got an AppleScript on your mind? , or if you like this site, rate me by clicking on a star rating at the top of the page.

Finder's Standard Suite; Basic AppleScript that most Applications should understand.

First the definition of a term as it appears in the Finder Dictionary, then an example or two of its use.

Apple Mac Cube and Monitor

This is rather lengthy. The items covered here are: Open,Print,Quit,Activate,Close,Count,Data Size,Delete,Duplicate,Exists,Make,Move,Select. Note that parameters enclosed in square brackets '[]' are optional (this is a common convention).

open v : Open the specified object(s)
open specifier : list of objects to open
[using specifier] : the application file to open the object with
[with properties record] : the ini tial values for the properties, to be included with the open command sent to the application that opens the direct object

Examples:

tell application "Finder" to open home

tell application "Finder"
open item "Document 1.cwk"
end tell

print v : Print the specified object(s)
print specifier : list of objects to print
[with properties record] : optional properties to be included with the print command sent to the application that prints the direct object

Example:


tell application "TextEdit"
print the front document with properties {copies:2, collating:true, starting page:1, ending page:1, pages across:1, pages down:1, error handling:standard} without print dialog
end tell




quit v : Quit the Finder
quit

Although the definition comes with the annotation 'Quit the Finder', it can be directed to an application:



tell application "FileMaker Pro" to quit

activate v : Activate the specified window (or the Finder)
activate [specifier] : the window to activate (if not specified, activates the Finder)

Example:

tell application "Finder" to activate




close v : Close an object
close specifier : the object to close

Example:

tell application "Finder"
set frontWind to (get name of front window)
close window frontWind
end tell

count v : Return the number of elements of a particular class within an object
count specifier : the object whose elements are to be counted
each type : the class of the elements to be counted
--> integer : the number of elements

Examples:

repeat with x from 1 to (count records)
...
end repeat

count text items

data size v : Return the size in bytes of an object
data size specifier : the object whose data size is to be returned
[as type] : the data type for which the size is calculated
-->integer : the size of the object in bytes

Example:

tell application "Finder" to get data size of front window

delete v : Move an item from its container to the trash
delete specifier : the item to delete
--> specifier : to the item that was just deleted

Example:

tell application "Finder"
activate
select (every file of front Finder window)
delete selection
end tell

duplicate v : Duplicate one or more object(s)
duplicate specifier : the object(s) to duplicate
[to location specifier] : the new location for the object(s)
[replacing boolean] : Specifies whether or not to replace items in the destination that have the same name as items being duplicated
[routing suppressed boolean] : Specifies whether or not to autoroute items (default is false). Only applies when copying to the system folder.
--> specifier : to the duplicated object(s)

Example:

tell application "Finder"
activate
duplicate item 1 of front Finder window to desktop
end tell

exists v : Verify if an object exists
exists specifier : the object in question
--> boolean : true if it exists, false if not

Example:

if not (folder "Database Backups" exists) then...

make v : Make a new element
make
new type : the class of the new element
at location specifier : the location at which to insert the element
[to specifier] : when creating an alias file, the original item to create an alias to or when creating a file viewer window, the target of the window
[with properties record] : the initial values for the properties of the element
--> specifier : to the new object(s)

Example:

tell application "Finder" to make new folder at desktop with properties {name:"New Folder",label index:1}

move v : Move object(s) to a new location
move specifier : the object(s) to move
to location specifier : the new location for the object(s)
[replacing boolean] : Specifies whether or not to replace items in the destination that have the same name as items being moved
[positioned at list] : Gives a list (in local window coordinates) of positions for the destination items
[routing suppressed boolean] : Specifies whether or not to autoroute items (default is false). Only applies when moving to the system folder.
--> specifier : to the object(s) after they have been moved

tell application "Finder"
set targetFolder to the target of front Finder window
set targetFiles to (every document file of targetFolder)
move targetFiles to desktop positioned at {500, 350}
end tell

select v : Select the specified object(s)
select specifier : the object to select

Examples:

select text 1 thru 36 of paragraph 10

tell application "Finder"
set desktopPath to (path to desktop)
select folder "untitled folder" of desktopPath
open the selection
end tell


If you have any questions or comments go to my Guestbook Got an AppleScript on your mind? or, if you like this site, rate me by clicking on a star rating at the top of the page.

RSS: AppleScript

Free Code Examples on Various Topics

AppleScripting How To:


Loading
Apple IIc After School Ad

Products Available through eBay

Product Line Updated Every Day

Neat products from Apple Computer that you can bid on. Laptops, Computers, Printers, MP3 Players,iPods,iBooks,iMacs etc.
Loading

Got an AppleScript on your Mind?

Comment on this site. What would you like to see covered?

This site is exclusively dedicated to the AppleScript enthusiast. If you have any problem with AppleScript syntax, post it here. I will try to help, even if it means doing a little investigation outside of my area of expertise.

  • Hester Mar 31, 2012 @ 9:40 pm | delete
    I'm trying to build an Automator/Quickeys solution that involves determining the FULL path of an item (which will then be put in the Spotlight comments...) But neither has a way to get the path that includes volume names! Since I have 20 drives attached to my computer, it's crucial to have a full path including the volume name. is there a simple applescript snippet that will do that? I can plug it into either application.
  • robert Mar 21, 2012 @ 9:53 pm | delete
    how to attach a word document to Outlook
  • RobertSheldon Dec 27, 2010 @ 2:14 pm | delete
    I would like to be able to call an applescript from within filemaker (because the send mail script step in filemaker does not work with outlook 2011 for Mac) which will create a new email pick up the "to" and "subject" from a record in fmpro, and i will complete the body of the message in outlook.
  • Hyperscripter Jan 17, 2011 @ 4:24 am | delete
    Unfortunately, I do not use Outlook. I do appreciate visitors to my site, though, so I will see what I can figure out, even if I can only get you (hopefully) headed in the right direction
  • RobertSheldon Jan 17, 2011 @ 12:36 pm | delete
    I solved this: http://fmforums.com/forum/topic/75463-outlookt-11/page__gopid__358458#entry358458
  • Load More

AppleWorks Suite

Commands that Should be Understood by all AppleWorks 6 Document Types.

Apple Leopard Ad Mac OS 10.5.8

Be sure to precede statement with tell application "AppleWorks 6" and activate, if the application is not currently running. What is covered here: select,copy to clipboard,cut,paste,insert,revert,start slides,stop slides,speak,menu,menu item.

select v : Select the specified object
select specifier : the object to be selected

An AppleWorks 6 text document:

tell document 1
select ( paragraphs 1 thru 5 )
end tell


copy to clipboard v : Copy the current selection to the clipboard [Application must be 'active'/at front]
copy to clipboard [specifier] : optional object to be selected (else the current selection is used)

As the entry implies, AppleWorks must be activated:

activate
tell document 1
select paragraph 5
copy to clipboard
end tell


cut v : Cut the current selection to the clipboard [Application must be 'active'/at front]
cut [specifier] : optional object to be selected (else the current selection is used)

activate
tell document 1
select paragraph 2
cut
end tell


paste v : Paste from the clipboard to the current selection [Application must be 'active'/at front]
paste [values/formulas/formats] : special things that can be pasted
[transpose boolean] : transpose the data diagonally?

select word 1 of paragraph 1
copy to clipboard
paste after paragraph -1

Add to Technorati Favorites



insert v : Insert a file into a document
insert alias : the file to insert
[at location specifier] : the location at which to insert the file
[using translator text] : the name of the translator to use to import the document
[with fields list of text] : the field order to use when inserting into a database (use "" to skip a field)

tell application "Finder"
set insertDoc to (choose file "Get data:")
tell application "AppleWorks 6"
activate
tell document 1
insert insertDoc
end tell
end tell
end tell


revert v : revert to the last saved version of a document
revert document : the document to be reverted

tell application "AppleWorks 6"
activate
tell document 1 to revert
end tell


start slides v : Start the slideshow for the current document
start slides
stop slides v : Stop the slideshow, returning to the normal application state
stop slides

These are shown together for obvious reasons:

tell application "AppleWorks 6"
activate
tell document 1 to start slides
delay 20
tell document 1 to stop slides
end tell


To move to the next page (slide), you click on the current page

speak v : Use PlainTalk to speak some text
speak specifier : the text to speak
[using voice text] : the name of the PlainTalk voice to use

tell document 1 to speak ( paragraphs 1 thru 5 ) using voice "Junior"

menu n : a menu
elements
contains menu items.
properties
name (text, r/o) : the name of the menu
id (integer, r/o) : the menu id
menu item n : a menu item. Use "select" to perform a menu item action.
elements
contained by menus.
properties
name (text, r/o) : the name of the menu
index (integer, r/o) : the menu item number
enabled (boolean, r/o) : is the menu item enabled?
checked (boolean, r/o) : is the menu item checked?
check character (text, r/o) : the character used to check this menu item

tell application "AppleWorks 6"
activate
tell document 1 to select menu item "Open..." of menu "File"
end tell

Related Topics

Other Topics that may be of Interest to AppleScripters

Basic HTML for Squidoo
Before you start reading all this, you may want to open Advanced HTML in a new tab, because you'll be wanting to check it out as soon as you've finished this!You can use basic HTML in a few of the lens modules. Mostly used to create hyperlinks (they are the "live links" to other si
Getting Started with Writing HTML
Help for those who have searched the internet for help on beginning to write HTML, but just can't find simple, straightforward information to get started with the basics, the 'building blocks'.The code presented here goes top to bottom according to the complexity of the subject matter covered. Take

Vote on these Books from Amazon

Books for the AppleScripter

AppleScript: The Missing Manual by Adam Goldstein

AppleScript: The Missing Manual by Adam Goldstein

From newspapers to NASA, Mac users around the world use AppleScript to automate their daily computing routines. Famed for its similarity to English and its ease of integration with other programs, AppleScript is the perfect programming language for time-squeezed Mac fans. As beginners quickly realize, however, AppleScript has one major shortcoming: it comes without a manual.

No more. You don't need a degree in computer science, a fancy system administrator title, or even a pocket protector and pair...

0 points

AppleScript in a Nutshell: A Desktop Quick Reference (Nutshell Handbook) by Bruce W Perry

AppleScript in a Nutshell: A Desktop Quick Reference (Nutshell Handbook) by Bruce W Perry

AppleScript in a Nutshell is the first complete reference to AppleScript, the popular programming language that gives both power users and sophisticated enterprise customers the important ability to automate repetitive tasks and customize applications. In this well organized and concise reference, AppleScript programmers will find:

  • Detailed coverage of AppleScript Version 1.4 and beyond
  • Complete descriptions of AppleScript language features.
  • Descriptions and hundreds of code samples on programming...
0 points

Apple Training Series: AppleScript 1-2-3 by Sal Soghoian, Bill Cheeseman

Apple Training Series: AppleScript 1-2-3 by Sal Soghoian, Bill Cheeseman

You could be saving yourself time and money right now using tools you probably didn't even know you had. AppleScript, a powerful and free scripting tool included on every Macintosh, enables individuals, professionals, and businesses to save time and money by automating time-consuming, repetitive tasks. Hallmark, for example, used AppleScript to reduce the number of color proofs needed to create a greeting card from a range of 5 to 25 expensive proofs per card down to just two. The best part? You...

0 points

Apple Automator with AppleScript Bible by Thomas Myer

Apple Automator with AppleScript Bible by Thomas Myer

One-stop reference helps you get the most out of AppleScript and Automator

One of the handiest ways to streamline your workload is to automate some of your most routine computer tasks. Mac users are lucky in that they have AppleScript and Automator automation tools built right in. This comprehensive guide shows you how to tap both these useful Mac features for Mac OS X and regularly perform such tasks as extracting unread e-mails from your Mail, scheduling workflows, and manually recording actions...

0 points

Beginning AppleScript (Programmer to Programmer) by Stephen G. Kochan

Beginning AppleScript (Programmer to Programmer) by Stephen G. Kochan

What is this book about?

Geared toward programmers with no prior development knowledge, Beginning AppleScript serves as a comprehensive guide to using AppleScript on the Mac OS X platform.%uFFFD This title introduces the reader to AppleScript, and then illustrates how to efficiently start writing scripts through sample programs as each concept is introduced. Exercises at the end of each chapter allow the reader to test and demonstrate their knowledge on how to write functional scripts. The appendices...

0 points

view all 6 items

TextEdit Standard Suite

Apple-Mac-TextEdit-AboutAlthough TextEdit is a fairly basic text application, it can be used very effectively in conjunction with AppleWorks 6 to 'fill in the gaps' in AppleWorks' (and others) scripting capabilities.

Since my focus here is TextEdit, I wont get into the details on how to integrate TextEdit scripting with other programs, but if you have read the section above on AppleWorks, you should have a pretty good idea of how to go about this. If you haven't looked at it, please do.

Now lets look at TextEdit's Standard Suite:


close v : Close an object.
close specifier : the object for the command
[saving ask/no/yes] : Specifies whether changes should be saved before closing.
[saving in alias] : The file in which to save the object.

Example:

tell application "TextEdit"
activate
set defaultDocName to (choose file name with prompt "Enter a name for this document before closing")
close document 1 saving yes saving in defaultDocName
end tell

count v : Return the number of elements of a particular class within an object.
count specifier : the object for the command
[each type] : The class of objects to be counted.
--> integer

Examples:

set countWords to (count words in front document)
display dialog countWords

count characters in word 1 of document 2

delete v : Delete an object.
delete specifier : the object for the command

Example:

delete word 1 of document 1

duplicate v : Copy object(s) and put the copies at a new location.
duplicate specifier : the object for the command
[to location specifier] : The location for the new object(s).
[with properties record] : Properties to be set in the new duplicated object(s).

Example:

exists v : Verify if an object exists.
exists specifier : the object for the command
--> boolean

Example:

tell application "TextEdit"
activate
exists document 1
end tell --> true because, when TextEdit is activated, it creates a new empty document ie 'Document 1'

get v : Get the data for an object.
get specifier : the object for the command
--> any

Example:

get word 3 of document 1

make v : Make a new object.
make
new type : The class of the new object.
[at location specifier] : The location at which to insert the object.
[with data any] : The initial data for the object.
[with properties record] : The initial values for properties of the object.
--> specifier

Example:

make new document with properties {text:"New Text Document"}

move v : Move object(s) to a new location.
move specifier : the object for the command
to location specifier : The new location for the object(s).

Example:

open v : Open an object.
open alias : The file(s) to be opened.
--> document

Example:

set openFile to (choose file)
open openFile

print v : Print an object.
print alias : The file(s) or document(s) to be printed.
[print dialog boolean] : Should the application show the Print dialog?
[with properties print settings] : the print settings

print front document with properties {copies:2, collating:true, starting page:1, ending page:1, pages across:1, pages down:1, error handling:standard} without print dialog

quit v : Quit an application.
quit
[saving ask/no/yes] : Specifies whether changes should be saved before quitting.

Example:

tell application "TextEdit"
activate
set defaultDocName to (choose file name with prompt "Enter a name for this document before quitting")
quit saving yes
end tell

save v : Save an object.
save specifier : the object for the command
[as text] : The file type in which to save the data.
[in alias] : The file in which to save the object.

Example:

save front document as text in "New Text File"

set v : Set an object's data.
set specifier : the object for the command
to any : The new value.

Example:

set DocName to document 1
--Result: document "Untitled" of application "TextEdit"

If you have any questions or comments, visit my Guestbook Got an AppleScript on your mind? , or if you like this site, rate me by clicking on a star rating at the top of the page.

Go around the world thru Orbitz!

Select a destination:

powered by Orbitz

by

Hyperscripter

Insanely obsessed with anything involving 'cracking the code', I am an AppleScript and Mac OS Afficionado. I have learned a lot, but have so much more... more »

Feeling creative? Create a Lens!