Basics of AppleScript

January 3, 2012
Say, you have some NFS share you would like to mount after typing a predefined password. Here's a little GUI program to demonstrate the basics of AppleScript.


set question to display dialog "" buttons {"Mount", "Unmount", "Cancel"} with title "Ready?" default button 3
set answer to button returned of question

if answer is equal to "Mount" then
	tell application "Finder"
		activate
		set Input to display dialog "" default answer "" buttons {"OK", "Cancel"} default button 1 with hidden answer
	end tell
	if text returned of Input as string is "qwerty" then
		do shell script "sudo mkdir /Network/nas/personal"
		do shell script "sudo mount -t nfs -o vers=3,resvport 192.168.100.200:/volume1/Personal /Network/nas/personal"
		tell application "Finder"
			--activate
			open folder "Macintosh HD:Network:nas:personal"
		end tell
	else
		return
	end if
end if

if answer is equal to "Unmount" then
	do shell script "sudo umount -f /Network/nas/personal"
	do shell script "sudo rmdir /Network/nas/personal"
end if

if answer is equal to "Cancel" then
	return
end if