Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
AppleScript
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== ===Hello, world!=== A [["Hello, World!" program]] can be written as a single line. To show a modal window with "OK" and "Cancel" buttons: <syntaxhighlight lang="AppleScript" line> display dialog "Hello, world!" </syntaxhighlight> To show a modal window with an "OK" button and an alert icon: <syntaxhighlight lang="AppleScript" line> display alert "Hello, world!" </syntaxhighlight> To output audio using a synthesized voice: <syntaxhighlight lang="AppleScript" line> say "Hello, world!" </syntaxhighlight> ===Failsafe calculator=== <syntaxhighlight lang="AppleScript" line> tell application "Finder" -- Set variables set the1 to text returned of (display dialog "1st" default answer "Number here" buttons {"Continue"} default button 1) set the2 to text returned of (display dialog "2nd" default answer "Number here" buttons {"Continue"} default button 1) try set the1 to the1 as integer set the2 to the2 as integer on error display dialog "You may only input numbers into a calculator." with title "ERROR" buttons {"OK"} default button 1 return end try -- Add? if the button returned of (display dialog "Add?" buttons {"No", "Yes"} default button 2) is "Yes" then set ans to (the1 + the2) display dialog ans with title "Answer" buttons {"OK"} default button 1 say ans -- Subtract? else if the button returned of (display dialog "Subtract?" buttons {"No", "Yes"} default button 2) is "Yes" then set ans to (the1 - the2) display dialog ans with title "Answer" buttons {"OK"} default button 1 say ans -- Multiply? else if the button returned of (display dialog "Multiply?" buttons {"No", "Yes"} default button 2) is "Yes" then set ans to (the1 * the2) display dialog ans with title "Answer" buttons {"OK"} default button 1 say ans -- Divide? else if the button returned of (display dialog "Divide?" buttons {"No", "Yes"} default button 2) is "Yes" then set ans to (the1 / the2) display dialog ans with title "Answer" buttons {"OK"} default button 1 say ans else delay 1 say "You haven't selected a function. The operation has cancelled." end if end tell </syntaxhighlight> ===Drive login=== This script controls the Finder application to login with [[username]] "John" and [[password]] "app123": <syntaxhighlight lang="AppleScript" line> tell application "Finder" set passAns to "app123" set userAns to "John" if the text returned of (display dialog "Username" default answer "") is userAns then display dialog "Correct" buttons {"Continue"} default button 1 if the text returned of (display dialog "Username : John" & return & "Password" default answer "" buttons {"Continue"} default button 1 with hidden answer) is passAns then display dialog "Access granted" buttons {"OK"} default button 1 else display dialog "Incorrect password" buttons {"OK"} default button 1 end if else display dialog "Incorrect username" buttons {"OK"} default button 1 end if end tell </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
AppleScript
(section)
Add topic