Apple Novice Needs Help

Don’t laugh, I’m still learning :oops: I was just trying to write a little script that I would set as a Startup Item in Sys Prefs. I just wanted something to quickly check my Inbox for any new messages and then give me some options. It was sort of working at one point but something has gone silly and I don’t know what. Maybe one of you guys could tell me by running it or looking at the script. Thanks in advance.


tell application "Mail"
	activate
	delay 5
	set myUnread to get unread count of inbox
	tell application "System Events"
		activate
		tell process "Mail"
			click menu item "Hide Mail" of menu "Mail" of menu bar 1
		end tell
	end tell
	if myUnread is greater than 0 then
		set tempVar to display dialog "Welcome Back, You Have " & myUnread & " New Email Messages. Would You Like to See Them Now?" buttons {"No Thanks", "Sure"} default button 2
	else
		set tempVarTwo to display dialog "You Do Not Have Any New Messages. Shall I Quit Mail for You?" buttons {"No Thanks", "Sure"} default button 2
	end if
	set buttonNew to button returned of tempVar
	set buttonNot to button returned of tempVarTwo
	if buttonNew is "Sure" then
		tell application "Mail"
			activate
		end tell
	else
		tell application "Finder"
			activate
		end tell
		if buttonNot is "Sure" then
			tell application "Mail"
				quit
			end tell
		else
			tell application "Finder"
				activate
			end tell
		end if
	end if	
end tell

You’re making things too complicated. You don’t need to invoke GUI scripting and you can simplify your if statements. You are also probably generating an error because you are trying to access two variables when the logic of your script dictates that only one will be defined. Try this:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

EDIT Ok, I see you’ve revised it even more. Still works great. If you don’t mind; Would you say that the second version is more stable for any particular reason? Or is it just better because it’s “leaner”? It’s obvious, there are many different ways to accomplish a task, how do you know which is the best? Thanks again man. :slight_smile: