Hi! Anyone knows how is it possible to make a script to enter, for example, in the yahoo mail (login, password)? Thanks!
Alex
I have many a “log in” script saved in the “Safari Scripts”.
The “key” for me is the Scripting Addition “Extra Suites” which let the script write text.
For example when I log into my “Yahoo” account I use the following script.
tell application “Safari” to activate
tell application “Extra Suites”
ES type string “myusername”
ES type key “tab”
delay 1
ES type string “mypassword”
ES type key “return”
end tell
Just be sure that the cursor is in the username field before running the script.
Extra Suites is available shareware at:
http://www.kanzu.com/index.html
I used a script to occasionally login to BT/Yahoo, which I discovered had recently broken (following a system upgrade). Your question prompted me to see what fixes might be needed. Turns out that it merely required a complete rewrite!
Since I’d used UI scripting for some of this, I discovered that the UI elements were much more complex and deeply nested than before. I’ve no idea if your login page is similar, but the script below (which now seems to work fine for me) might help to get you started. If you have difficulty adapting it, you might consider posting the url of your login page, so that we can compare them. In case it helps, mine is:
http://edit.europe.yahoo.com/config/login?.intl=uk&.partner=bt-1&.done=http%3A//bt.yahoo.com/%3F
I had hoped that setting/confirming the value of a text field might now work more effectively in Tiger. However, since there still seem to be some issues here, I had to resort to a bit of a workaround (hence the ‘setTextValue’ handler).
Anyway, for what it’s worth…
property yahooLogin : "http://url/of/your/login/page" (* modify as required *)
property userName : "yourUsername" (* modify as required *)
property userPassword : missing value
property maxConnectTime : 10 -- seconds to wait for a connection
property connectCheckTime : 0.2 -- seconds between each check
to checkPassword()
if userPassword is missing value then set userPassword to (display dialog "Please enter your password for " & ¬
userName & ":" default answer "" with title "Enter Password" with icon 1 with hidden answer)'s text returned
end checkPassword
to setTextValue for f to v
tell application "System Events"
tell f's text field 1 to repeat until focused
keystroke tab
end repeat
keystroke v
end tell
end setTextValue
to connectToServer()
tell application "Safari"
activate
make new document with properties {URL:yahooLogin}
tell document 1 to repeat maxConnectTime div connectCheckTime times
try
if URL is yahooLogin then return
on error
delay connectCheckTime
end try
end repeat
beep
with timeout of weeks seconds
display dialog "The Yahoo! connection attempt timed out. " & ¬
"Please make sure you have a valid internet connection and try again." buttons ¬
{"OK"} default button 1 with icon 0
end timeout
error number -128
end tell
end connectToServer
to login()
tell application "System Events" to tell group 7 of UI element 1 of scroll area 1 of group -1 of process "Safari"'s front window
setTextValue of me for group 6 to userName
setTextValue of me for group 9 to userPassword
click button "Sign In" of group 14
end tell
end login
checkPassword()
connectToServer()
login()
Incidentally, if all that messing around with specific UI elements seems a bit much, you might like to try winging it with blind keystrokes. This modified version of the above script should show the sort of thing I mean:
property yahooLogin : "http://url/of/your/login/page" (* modify as required *)
property userName : "yourUsername" (* modify as required *)
property userPassword : missing value
property maxConnectTime : 10 -- seconds to wait for a connection
property connectCheckTime : 0.2 -- seconds between each check
to checkPassword()
if userPassword is missing value then set userPassword to (display dialog "Please enter your password for " & userName & ":" default answer "" with title "Enter Password" with icon 1 with hidden answer)'s text returned
end checkPassword
to connectToServer()
tell application "Safari"
activate
make new document with properties {URL:yahooLogin}
tell document 1 to repeat maxConnectTime div connectCheckTime times
try
if URL is yahooLogin then return
on error
delay connectCheckTime
end try
end repeat
beep
with timeout of weeks seconds
display dialog "The Yahoo! connection attempt timed out. Please make sure you have a valid internet connection and try again." buttons {"OK"} default button 1 with icon 0
end timeout
error number -128
end tell
end connectToServer
to login()
tell application "System Events" to repeat with k in {userName, tab, userPassword, return}
delay 1
keystroke k
end repeat
end login
checkPassword()
connectToServer()
login()
Thanks, Kai! I’am working on it.
Alex