AppleScript

from Wikipedia, the free encyclopedia
AppleScript
Publishing year: 1993
Developer: Apple
Current  version : 2.7   (October 16, 2014)
Typing : weak , dynamic , implicit
Influenced by: HyperTalk, natural language , natural-language programming
Operating system : Mac OS X
License : proprietary (parts are published under the APSL )
developer.apple.com/applescript

AppleScript is a scripting language from Apple . It is part of the Mac OS operating system . AppleScript is used to automate and expand Mac OS programs and to control them remotely within a computer network.

The first version of AppleScript was based on the HyperCard project. HyperCard included the scripting language HyperTalk, a scripting language based on the English language. This makes AppleScript programs relatively easy to understand even for people who cannot program.

Language syntax

AppleScript is based on the natural English language. An object-oriented method is called as follows:

character 1 of item 2 of {"one", "two", "three"}

In German it would read like this:

Zeichen 1 aus Element 2 aus {"one", "two", "three"}

In Java, however, as follows:

String[] x = {"one","two","three"};
char y = x[1].charAt(0);

Cross-application communication

AppleScript is primarily used to "remote control" other programs from within a program. Mac OS offers AppleEvents, a cross-application communication protocol with which it is possible to send messages from one application to another application so that it behaves as desired.

For example, you can use a script to instruct an application to open a specific document. With the word "tell" such a message is e.g. B. sent to Word:

tell application  "Microsoft Word"
    open file "Diplomarbeit" of folder "Dokumente" of disk "Studium"
end tell

In German:

Sage Anwendung "Microsoft Word"
   Öffne Datei "Diplomarbeit" aus Ordner "Dokumente" aus Laufwerk "Studium"
Ende Sage

AppleScript for automation

AppleScript is not just designed for cross-application tasks. It can u. a. can also be used to automate frequently recurring tasks or to have calculations carried out. An example:

set pix to 72
set answer to text returned of (display dialog "Enter the length in inches" default answer "1")
display dialog answer & "in = " & (answer * pix) & "px"

In German it would read like this:

Setze Pixel auf 72
Setze Antwort auf eingegebenen Text von (zeige Dialog "Gib die Länge in Zoll ein" Standardantwort "1")
Zeige Dialog Antwort & " Zoll = " & (Antwort * Pixel) & " Pixel"

It shows a dialog box and asks for the length in inches. It is then calculated how many pixels there will be on this length. A second dialog box then shows the result.

AppleScript dialects

For a short time, Apple even expanded AppleScript so that the scripts didn't have to be written in English. You should be able to write the scripts in your own mother tongue. The script terminology was translated into French, Japanese and Italian and Mac OS was able to translate it from one dialect to another. This worked, but the developers of Macintosh software (outside of Apple) did not support the multilingualism of AppleScript adequately because of the great effort involved. Since the support was also cumbersome, this idea was no longer pursued in Mac OS 8.5 and higher.

literature

  • Detlef Schulz: AppleScript - the automatic Mac . SmartBooks, Pfäffikon SZ 2009, ISBN 978-3-908497-78-3 , p. 844 .

Web links