Applescript is a programming language used to create scripts in Mac computers.

Generic Syntax

Command Effect
-- This is a single line comment Single line comment
# This is another single line comment Single line comment
(* This is a multi line comment *) Multi-line comment
open location "" Open URL with the appropriate program[5,6]
do shell script "say \"we did it\"" Run arbitrary shell script[3]
do shell script "..." with administrator privileges Run arbitrary shell script using sudo
set variableName to value Set a variable
tell application "iTerm" to ... Tell application to do something (see below)

Destructure a list to new variables

set newList to {100, 200, 300}
set { x, y, z } to newList # x=100, y=200, z=300
set a to item 2 of newList # a=200


if true then
  # do stuff
else if false then
  # do other stuff
  # do another thing
end if

Tell System To Do Something

Dialog Box[9]

set theDialogText to "The curent date and time is " & (current date) & "."
display dialog theDialogText

Get User Input[10]

set theResponse to display dialog "What's your name?" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
--> {button returned:"Continue", text returned:"Jen"}
display dialog "Hello, " & (text returned of theResponse) & "."

Tell Application To Do Something

tell application "iTerm" to # put single action here

tell application "iTerm"
  # put multiple actions here
end tell



A droplet is an application that performs actions on files or folders that the user drops onto the application itself in the Finder. This is useful if you are scripting for people who aren't power users/terminal users or for simple tasks.

To signify that an application is a droplet, your code must include an open event handler.

on open theDroppedItems
    -- Process the dropped items here
end open


  2. Error Messages
  8. Switch audio devices
  9. Display dialog text
  10. Getting user input
  11. If else
  12. Applescript fundamentals
  13. Droplets

Last modified: 202212070107