Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

quvuen

macrumors newbie
Original poster
May 7, 2008
1
0
Since getting a mac I've been wanting to learn applescript and have checked out some online resources. Sadly I'm unable to locate the two things that help me most when learning a new language: a site with plenty of sample scripts and a page that lists all language commands along with their explanations.

I've gone through the sample scripts that are in the applescript folder but they fail to cover all the topics I'm interested in. I'm having trouble finding a command directory because they are either incomplete or don't list any examples.

Also I was hoping to get some feedback at the first simple applescript I've written:

Code:
set CR to ASCII character of 13
tell application "System Events"
	display dialog "Log In" buttons {"Acc1", "Acc2", "Cancel"} default button 3
	if the button returned of the result is "Acc1" then
		tell application "app" to activate
		keystroke "Username"
		keystroke tab
		keystroke "Password" & CR
	else
		tell application "app" to activate
		keystroke "Username"
		keystroke tab
		keystroke "Password" & CR
	end if
end tell
All that the script does is present you with three buttons: a cancel button and two buttons, one for each account. Upon pressing an account button the script launches the assigned application and types in use name, password and hits enter. The script works well - I'm just wondering if there's a better way to write it. Also, is an "else" statement always required for an "if"?

Thanks in advance
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.