I often end up with a Safari window in front that I don’t want to close or minimize, but that I do want to send behind all other windows. Alas, Safari doesn’t have this command in the Window menu. I’ve requested that it be added (FB7642150) and you can also 😉
In the meantime, I don’t much like AppleScript so I don’t know it well, but this need finally hit the level where I was willing to suffer through the pain of AppleScript and hack something together (there’s probably a better way to write this). I put this into a simple Alfred workflow and it works great (yay!):
on alfred_script(q)
tell application "Safari"
local lastVisibleWindow
repeat with n from 1 to count of windows
if window n is visible then
set lastVisibleWindow to window n
else
exit repeat
end if
end repeat
set index of front window to index of lastVisibleWindow
end tell
end alfred_script
You can also use this script from a scripts menu, or other utility able to invoke applescripts, by removing the first and last lines that make it a handler for Alfred.
Tested and works under Safari 13.0.5 on macOS 10.15.3
This script handles the case where you have minimized windows. The “set index of the frontmost window to (count of windows)” type script you’ll find elsewhere online doesn’t work if you have minimized windows.
cheers.