I tried diggin through as many topics as I could to track down the answer to my questions but I don’t think I know exactly how to phrase my problem so I thought I’d ask for some help specifically.
First just so you know my AS abilities, I’ll list what i’ve accomplished so far
…
Ok, it’s short list.
moving on. Currently I am trying to put together a script to automagically logs on to a number of web based email accounts. At this point, I’m stuck trying to figure out how to tell AS to check the name of the foremost Safari window against a list of expected names. What I mean is, once the page has loaded, is the title of page “Log In” or “Inbox”? And depending on the answer, take the next appropriate step, log in or create a new tab and open the next webpage.
I’ve been trying to accomplish this with a simple:
tell application "System Events" to tell process "Safari"
set frontmost to true
set windowName to name of window
end tell
if windowName is {"Log In"} then
tell application "System Events" to tell process "Safari"
set frontmost to true
keystroke tab
keystroke "screen name"
keystroke tab
keystroke "password"
keystroke return
keystroke "t" using {command down}
end tell
end if
if windowName contains {"inbox"} then
tell application "System Events" to tell process "Safari"
set frontmost to true
keystroke "t" using {command down}
end tell
end if
Unfortunately every time I run this I receive an applescript error “Can’t get name of window”
My brain can’t seem to get past this and I’m in need of some assistance. Any thoughts, code, etc to push me past this? I really appreciate any help you might be able to provide.
Thanks Kel, I was pretty sure it was something simple and obvious, and that tip took care of my problem.
My next question is a matter of cleaning up my script.
Currently I am forcing my script to delay 30 seconds or so to fully load the pages before continuing the checks. Is there any way to have AS make a check to see if a page is fully loaded or not so that it doesn’t sit there waiting for a delay to complete?
Jacques, thanks for the tip on how to check for Stop/Reload status in the toolbar.
I actually ended up having to ajust it a bit to get it to work:
repeat
if value of attribute "axdescription" of button "Stop/Reload" of group 2 of tool bar of window1 as string is {"reload"} then exit repeat -- fully load page
end repeat
repeat
if value of attribute "axdescription" of button "Stop/Reload" of group 2 of tool bar of window1 as string is {"reload"} then exit repeat -- fully load page
end repeat
or the first poster’s:
repeat
if value of attribute "axdescription" of button "Stop/Reload" of group 2 of tool bar of window ¬
"Log In" as string is "reload" then exit repeat -- fully load page
end repeat
The script works fine without the repeat loop, but I need to wait til the page loads.
Is there a reason that the repeat loop code wouldn’t be able to work with Firefox as the browser?