Basics of AppleScript

Conditions In Lists

Relation Operators for Lists

Serial No AppleScript
1 begins with
2 ends with
3 contains
4 is equal to
5 is in

Script [10.3.1]:

display dialog "My Name is Nayan Seth" buttons {"Cancel", "No", "Yes"} default button 3
if the button returned of the result is "Yes" then
    say "That is true"
else if button returned of the result is "No" then
    say "You clicked the wrong button"
end if

Explanation: In this example I am displaying a dialog with 3 buttons. Depending on the button you click, the if...else condition will be checked.

Figure 10.3.1

Figure 10.3.1 Dialog Button (if...else)

Script [10.3.2]:

set temp to display dialog "My Name is Nayan Seth" buttons {"Cancel", "No", "Yes"} default button 3
set buttonName to button returned of temp
if the buttonName is equal to "Yes" then
    say "That is true"
else if buttonName is equal to "No" then
    say "You clicked the wrong button"
end if

Explanation: In this example I am displaying a dialog with 3 buttons. Depending on the button you click, the if...else condition will be checked.

Here instead of directly using AppleScript commands, I am making use of variables. And I have used these variables to check if the button returned was “Yes”, “No” or “Cancel”

Figure 10.3.2

Figure 10.3.2 Dialog Button (if...else)

Dialogs with buttons and actions can be directly created.

Simplifying Scripting

Figure: Simplifying Scripting