Critique my script, please!

Hello all!

I have a script I recently wrote and it is working well. I’m just wondering if there are things I’m overlooking or any suggestions for improvement you could think of.

-- Please note, you must add your own PPD for your store's printer, or comment the line out.

set timLoc to "Los Angeles - U.S.A." -- Your time zone as shown in Time & Date preferences.
set arsNum to "034" -- Your three digit store number.

tell me
	activate
	try -- Ask for computer number.
		set cpuNum to ("ars" & arsNum & "." & text returned of (display dialog ¬
			"Please enter the two digit number that correponds to this computer." buttons {"Cancel", "Continue"} ¬
			default button "Continue" cancel button "Cancel" giving up after 15 ¬
			default answer ("") ¬
			with icon 1 ¬
			with title "Computer Number"))
	on error -128 -- If user cancels, exit script, cannot continue without this step.
		return
	end try
	
	try -- Ask for MobileMe password.
		set mblPas to (text returned of ¬
			(display dialog ¬
				"Please enter the MobileMe password for this store" buttons {"Cancel", "Continue"} ¬
				default button "Continue" cancel button "Cancel" giving up after 15 ¬
				default answer ("") ¬
				with icon 1 ¬
				with title "MobileMe Password" with hidden answer))
	on error -128 -- If user cancels, exit script, cannot continue without this step.
		return
	end try
end tell

-- The following shell commands are to setup:
-- ¢ Attempt to start AppleTalk on en0, en1, and en2, this should cover laptops and desktops.
-- ¢ Add AppleTalk printer from PPD file inside Applescript bundle, set name, description, and network location.
-- ¢ Set the computer to startup everyday at 7:00 a.m.
-- ¢ Set the screensaver to never
-- ¢ Load the cron file in the bundle which tells the computer to shutdown every night at 11:00 p.m.
-- ¢ Use systemsetup to set all sleep options to never, turn on remote login, set the timezone, and set the computer name.
-- ¢ Start SSH service (may be redundant with remote login turned on?)
-- ¢ Enable access for assistive devices.
-- ¢ Turn on ARD and enable all users.
-- ¢ Turn of Software Update checking.

do shell script ¬
	"/usr/sbin/appletalk -u en0; appletalk -u en1; appletalk -u en2; " & ¬
	"/usr/sbin/lpadmin -p 'Genius_Bar'  -D 'Genius Bar' -v 'pap://*/GB%20POS%20203/LaserWriter' -P " & the POSIX path of (path to me) & "Contents/Resources/Genius_Bar.ppd  -L 'Genius Bar' -E -d 'Genius_Bar'; " & ¬
	"/usr/bin/pmset repeat wakeorpoweron MTWRFSU 07:00:00; " & ¬
	"/usr/bin/pmset displaysleep 0; " & ¬
	"/usr/bin/crontab " & the POSIX path of (path to me) & "Contents/Resources/cron.txt; " & ¬
	"/usr/sbin/systemsetup -setsleep 0 -setremotelogin on -settimezone " & timLoc & " -setcomputername " & cpuNum & "; " & ¬
	"/sbin/service ssh start; " & ¬
	"/usr/bin/touch /private/var/db/.AccessibilityAPIEnabled; " & ¬
	"/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all; " & ¬
	"softwareupdate --schedule off" with administrator privileges

tell application "System Preferences"
	launch
	set the current pane to pane id "com.apple.preference.internet" -- Select MobileMe
	reveal anchor "account" of current pane -- Ensure account tab is selected
	tell application "System Events"
		tell process "System Preferences"
			activate -- Bring System Preferences to front incase of dialogs.
			
			if exists static text 3 of tab group 1 of window 1 then -- If logged in this will exist.
				if value of static text 3 of tab group 1 of window 1 is cpuNum then -- If already logged into MobileMe as the correct user, then skip this setup.
					
				else -- Otherwise, begin setup.
					click button 1 of tab group 1 of window 1
					click button 1 of sheet 1 of window 1 -- Logs out
					
					tell group 1 of window 1
						set value of text field 2 to cpuNum
						set focused of text field 1 to true
						set value of text field 1 to mblPas
						set focused of text field 1 to true -- Setting focused submits the information, logging in.
					end tell
					
				end if
				
			else -- If static text 3 does not exists (no one is logged in yet) then log in.
				tell group 1 of window 1
					set value of text field 2 to cpuNum
					set focused of text field 1 to true
					set value of text field 1 to mblPas
					set focused of text field 1 to true
				end tell
			end if
			delay 0.5 -- Wait for login.
			click radio button 4 of tab group 1 of window 1 -- Switch to Back to My Mac
			delay 0.5
			if title of button 1 of group 1 of tab group 1 of window 1 is "Stop" then -- If started, stop.
				click button 1 of group 1 of tab group 1 of window 1
			end if
			click radio button 1 of tab group 1 of window 1 -- Switch back to accounts tab.
			
			click button 1 of group 1 of group 2 of tool bar 1 of window 1 -- Revert back to show all
		end tell
	end tell
end tell

Or not… :expressionless:

Hi,

ok, if you want a review.

the script looks very good. :slight_smile:

There is just a little error, but not important.
The on error part in the dialog boxes at the beginning will never be reached, unless you write

on error number -128 

You can actually omit the whole try block, because if the user presses “Cancel”, the script terminates anyway.
The cancel button doesn’t have to be specified, if the button is “Cancel”


.
set cpuNum to ("ars" & arsNum & "." & text returned of (display dialog ¬
	"Please enter the two digit number that correponds to this computer." buttons {"Cancel", "Continue"} ¬
	default button 2 giving up after 15 ¬
	default answer ("") ¬
	with icon 1 ¬
	with title "Computer Number"))
.