How to tell Safari to close it's window, but not quit?

If I wanted to tell Safari to close it’s browser window, but not quit the whole Safari application, how could I go about doing that? I was thinking something along the lines of this, but it’s obviously not the solution, as it doesn’t work:

tell application “Safari”
do JavaScript “window.close();”
end tell

Um, this works for me:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

This will also work:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

This is great! Now it turns out that I need to do the same thing with Internet Explorer. Unfortunatly neither of these techniques seem to work with that browser. It appears that IE doesn’t have a “do javascript” call. Hmmmm. It also doesn’t seem to like a “close window 1” call. Unfortunately, in 10.3.4, if I try to drag IE to the script editor to try to acquire it’s dictionary, it tells me that it’s unscriptable. I can’t believe that.

To get IE’s dictionary, in Script Editor, select “Open Dictionary…” then navigate to IE. Either of these will work for doing what you want in IE:

or

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

EASIEST way to close all windows


tell application "Safari"
	activate
	tell application "System Events"
		keystroke "w" using {command down, option down}
	end tell
end tell

No Sir, I’m sorry, this is the easiest way


tell application "Safari" to close every window

dangit!

I hate being a noob!
(that’s cool though, I didn’t know you could do that)

Safari is pretty scriptable, take a look at it’s dictionary

PS: GUI scripting is the last and worst case :wink: