Trying to automate server setting changes with Applescript. NOOB!

Hi.
I’m trying to create an applescript for logging into my server and shutting down my power management settings. I’m very new to this, so I would very much appreciate a push in the right direction.

So far, I’ve got this:

tell application “Safari”
activate
do JavaScript “window.open(‘http://192.168.1.162’)” in document 1
end tell

tell application “Safari”
set contents of user name of window 1 to “test”
set contents of password of window 1 to “test”
end tell

which, unfortunately, does not successfully log me in…it does however, open the webpage successfully, so that’s exciting! :slight_smile:

Can anyone tell me the correct syntax for getting the login to work properly? Also, once I’m logged in, how do I set it up to tab through the fields actions so that I can set the right settings and then log out?

Thanks in advance!

Welcome icomposer;

If Safari is your default browser, then you can open a window to your server like this:

open location "http://192.168.1.162"

Does that page then produce a dropdown asking for name and password or are there boxes on the page?

Thanks for the response. There’s no dropdown, it’s just 2 fields in the page.

ok, from searching the archives, I’ve gotten a lot closer to my goal. So far, I’m able to login and navigate to the correct tabs via keystroke. It works, but I’m starting to wonder if perhaps there’s a more elegant way to get there without having to do tab & tab & tab…?

Here’s what I have working so far:


open location "http://192.168.1.162"

delay 1

tell application "System Events"
	keystroke "XXXX" & tab
	delay 0.5
	keystroke "XXXX" & return
	delay 0.5
	keystroke tab & tab & tab & return
	delay 0.5
	keystroke tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & return
	delay 0.5
	keystroke tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & tab & return
end tell

So, since this is working, I guess I could just close it up and call it a night, but for the sake of learning this language, I wonder if any of you good folks would mind steering me towards a more elegant way of doing this? Is there a way of going directly to a field, tab or button without tabbing through to them? If tab is the only way, how do I set up the ‘option’ modifier key so that it tabs through with less keystrokes?

Thanks again!

Hi iocomposer

The UI browser from the site below is great for what your doing.

http://prefabsoftware.com/uibrowser/

also see this thread, it may be helpful to you.

http://bbs.applescript.net/viewtopic.php?id=19889

Budgie

Thanks much for the tip.
I downloaded the uibrowser and it is in fact, very helpful in finding out the names of the buttons and things. However, I’m not sure what to do with the information. None of the output that it gives me works. For example, it gave me this to put in my script:

click button “Save Settings” of group “” 9 of UI element “” 1 of scroll area 1 of group 3 of window “WebInterfaceForServer3”

It certainly doesn’t work. Maybe I need to put some information between the quotes? I wouldn’t even begin to know what would go in there.

Thanks again.