getting my mail with UI scripting

ok, i have this so far (i think this might have been a script of Adam Bells, im not sure)

property logon_address : "http://www.hotmail.com"
property logon_name : "spikeit_13@hotmail.com"
property logon_password : "mypassword" 

tell application "Safari"
	activate
	open location logon_address
	tell document 1
		repeat until name starts with "Loading" or name starts with "Untitled"
			delay 0.2
		end repeat
		repeat while name starts with "Loading" or name starts with "Untitled"
			delay 0.2
		end repeat
	end tell
end tell

tell application "System Events"
	delay 1.5 (* modify delay as required *)
	keystroke logon_name & tab
	delay 1.5 (* modify delay as required *)
	keystroke logon_password & return
end tell

it works fine and dandy but on hotmail there is a radio button to remember your email address. So i want to check to see if its selected and if not run the script above and if it is run the same script but without the user name. I don’t know how to UI script that well so just looking for some help.

Well the unfortunate thing about this is that if Hotmail decided to change their page this code could become irrelevant, but here it is.

tell application "System Events"
	tell process "Safari"
		if (get value of radio button 1 of group 15 of UI element 1 of scroll area 1 of group 4 of window "Sign In") is 1 then
			-- "Save my e-mail address IS selected proceed without username
		else
			-- "Save my e-mail address is NOT selected proceed with username
		end if
	end tell
end tell

Thanks James!
Hotmail hasn’t changed that window for some time so if they do, well i guess ill just adjust the script;)
thanks again!

WOW that was a fast reply, no problem :smiley:

actually im getting an error. It is NSReceiverEvaluationScriptError: 4 and it highlights the word value in

if (get value of radio button 1 of group 15 of UI element 1 of scroll area 1 of group 4 of window "Sign In") is 1 then

Hehehe, let me guess when you ran the script did you have only one tab open? If you did then it removes the tab grouping and your view area changes from group 4 to group 3… so if thats the case then the code becomes

tell application "System Events"
	tell process "Safari"
		if (get value of radio button 1 of group 15 of UI element 1 of scroll area 1 of group 3 of window "Sign In") is 1 then
			-- "Save my e-mail address IS selected proceed without username
		else
			-- "Save my e-mail address is NOT selected proceed with username
		end if
	end tell
end tell

So I guess thats another important thing to consider beyond hotmail… removing the the url bar, bookmar bar, tabs, etc… all will effect your grouping arrangement and thus your code.

A work around though might be to count your groups and work around that as a fail safe, try this…

tell application "System Events"
	tell process "Safari"
		set c to count of group of window "Sign In"
		if c > 1 then set c to c - 1
		if (get value of radio button 1 of group 15 of UI element 1 of scroll area 1 of group c of window "Sign In") is 1 then
			-- "Save my e-mail address IS selected proceed without username
		else
			-- "Save my e-mail address is NOT selected proceed with username
		end if
	end tell
end tell

what if i just put it in a new window? then what would it look like?

EDIT: Nevermind, I got it.

Hendo did my last example not work? (I posted twice =))

oh, i didnt even see that other one:P

Whoops, It wont work anyways there was a mistake on my part, THIS time it should work under a variety of scenarios.

tell application "System Events"
	tell process "Safari"
		set c to count of group of window "Sign In"
		if (get value of radio button 1 of group 15 of UI element 1 of scroll area 1 of group c of window "Sign In") is 1 then
			-- "Save my e-mail address IS selected proceed without username
		else
			-- "Save my e-mail address is NOT selected proceed with username
		end if
	end tell
end tell

works now! thanks!

No problem =)

Nice work, James. :slight_smile:

Looks spookily similar to this routine, hendo. :wink:

Quite “ although, regardless of how various switchable elements might be configured, a Safari window’s main scroll area is usually within the last group. Counting back from the end can sometimes be more straightforward than starting at the beginning.

One way to reduce such a risk “ especially if there’s no way to identify a UI element directly “ is to try and locate an identifiable element nearby, and then use relative referencing to locate the target in question. That way, even if the interface is restructured in some way, the addition or removal of any elements should be less likely to disturb the relationship.

For example:


tell application "System Events" to tell radio button 1 of group before (first group of UI element 1 of scroll area 1 of group -1 of application process "Safari"'s window "Sign In" where class of UI elements contains static text and value of static text 1 is "Save my e-mail address") to if (exists) and value is 1 then
	
	"Save my e-mail address button is selected"
	
else
	
	"Save my e-mail address button is NOT selected"
	
end if