set AddessBarVisible to false
tell application "System Events"
tell application process "Safari"
tell window 1
tell tool bar 1
repeat with gr in every group
tell gr
try
-- get value needed to throw try error
get value of text field 1 of splitter group 1
set AddessBarVisible to true
end try
end tell
end repeat
end tell
end tell
end tell
end tell
display dialog AddessBarVisible
When I tried your script it refused to compile the line “repeat with gr in every group” under OS X 10.4.7 unless Safari was running, a window was showing, and the Address Bar was there. I got this to work for me:
tell application "System Events"
tell application process "Safari"
tell window 1
if not (exists tool bar 1) then beep 3
end tell
end tell
end tell
Or, munching it down a bit: (bearing in mind that the answer is false if a Safari window is not frontmost)
set AB to true
tell application "System Events" to tell process "Safari" to tell window 1 to if not (exists tool bar 1) then set AB to false
AB
Even with UIBrowser at hand, I’m hopeless at UI scripting (clearly having missed an “aha” somewhere along the way), so I’ll be interested to see the solution for turning the tool bar off.
activate application "Safari"
tell application "System Events" to tell application process "Safari"
set w to not (exists front window)
if w then click menu item "New Window" of menu "File" of menu bar item "File" of menu bar 1
repeat until exists front window
delay 0.1
end repeat
tell menu item "Hide Address Bar" of menu "View" of menu bar item "View" of menu bar 1 to if exists then click
if w then click menu item "Close Window" of menu "File" of menu bar item "File" of menu bar 1
end tell
Thank you, Kai, although this last line “if w [not exists front window] then click menu item “Close Window” of menu “File” of menu bar item “File” of menu bar 1” confuses me.
That’s probably because, at that point, the boolean value represented by the variable w no longer means [not exists front window], Adam.
The routine takes account of the fact that, if no Safari window is currently open, the status of the menu item Show/Hide Address Bar is not a reliable indicator of whether the address bar will show when a new window is opened. So the script first checks for an open window:
set w to not (exists front window)
Then, if w [no front window exists], a window is opened temporarily - just to determine the accurate status of the menu item:
if w then click menu item "New Window" of menu "File" of menu bar item "File" of menu bar 1
Later, once the appropriate actions have been taken, the temporary window is no longer required - so it can be closed:
if w then click menu item "Close Window" of menu "File" of menu bar item "File" of menu bar 1
So what w really means here is: [no front window existed before the script opened one].
It certainly works as described here, Adam. Since you seem to be questioning either what the script does or the above description, could you perhaps enlarge on that statement?