Make new Safari window and refer to it without ambiguity

Hello.

I can tell Safari to make a new document, but I cannot tell it to make a new window.

This does not work at all:

tell Safari
]set w to make new window
end tell

whereas this does open a new window:

tell Safari
set w to make new document
end tell

How can I refer to that specific new window in order to, say, reposition it?

Since it is the last window to have been opened, it usually works to call it ‘window 1’. However this seems like an unreliable workaround. Is there a more direct, surefire way?

More conceptually, I don’t get the need to have a class ‘documents’ in addition to the class ‘windows’. Does this distinction serve any use that I cannot see?

Thank you in advance. W.

Hi.

It’s should be OK if you get the new window’s id immediately:

tell application "Safari"
	set d to (make new document)
	set w to first window whose name is d's name --> Unchanging id reference to window.
	-- Or:
	set w to front window --> Ditto.
end tell

On my machine, none of you scripts work.
Both ask to open a variable which was never defined so they issue:
error “La variable Safari n’est pas définie.” number -2753 from “Safari”
What puzzles me isn’t that we get an error, it’s that this one is related to the application “Safari” to which there is no explicit reference in the scripts.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 12:20:38

Hi Yvan.

It’s not related to the application “Safari” but to the term that’s causing the error.

Thank you Nigel

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 14:01:35

I see the OP is looking for something that does not happen - a window without a document. First there was the Word and the word it was God. So it is here. First there must be a Document… A document is not file on the disk, but address of first byte of Ram, occupied by the new window (which is result of making new document). So, creating document is holding some place of the RAM for the new window contents.

Here is another example, with opening the URL and getting the window ID:


tell application "Safari"
	set newDocument to make new document with properties {URL:"favorites://"}
	set newWindowID to id of first window whose name is newDocument's name
end tell

Based on an understanding of how everything should work, you want create blank window? No problem:


tell application "Safari"
	set newDocument to make new document with properties {URL:""}
	set newWindowID to id of first window whose name is newDocument's name
end tell

A window is a canvas. A document is what is painted on it. To find out the color of the “Black Square”, you are evaluating a drawing, not a canvas. It is simply faster and more logical. You are not interested in other details (properties).

So the pretext for the existence of 2 classes is the separation of duties, which means the speed of the object (code that is a copy of the class from disk to RAM).