We were unable to guess that the asker run El Capitan.
Here is a script doing the job under this new OS and under older ones.
I tried to borrow a piece of code to Christopher Stone but I discovered that it fails if there is no Safari window already open:
error "Erreur dans Safari : Il est impossible d’obtenir window 1. Index non valable." number -1719 from window 1
tell application "Safari"
activate
close every window
repeat # Wait until the window is really available
delay 0.1
if exists window 1 then exit repeat
end repeat
end tell
set sysVersion to (system attribute "sys2")
tell application "System Events" to tell process "Safari"
set frontmost to true
if sysVersion > 10 then
# Here running under El Capitan (10.11)
keystroke "f" using {command down, control down} # force full screen mode
repeat
tell me to delay 0.1
if enabled of menu item 1 of menu 1 of menu bar item 5 of menu bar 1 then exit repeat
end repeat
value of attribute "AXMenuItemMarkChar" of menu item 1 of menu 1 of menu bar item 5 of menu bar 1
if result is not missing value then
click menu item 1 of menu 1 of menu bar item 5 of menu bar 1
end if
else
# Here running Yosemite or older OS
if toolbar of window 1 is not {} then
click menu item 1 of menu 1 of menu bar item 5 of menu bar 1
end if
keystroke "f" using {command down, control down} # force full screen mode
end if
end tell
Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) samedi 1 aoqt 2015 10:07:45