Saturday, July 4, 2020

#1 2020-05-02 02:51:32 am

wladdy
Member
Registered: 2012-03-02
Posts: 27

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:

Applescript:

tell Safari
]set w to make new window
end tell

whereas this does open a new window:

Applescript:

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.


Filed under: safari windows

Offline

 

#2 2020-05-02 03:20:02 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5233

Re: Make new Safari window and refer to it without ambiguity

wladdy wrote:

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?


Hi.

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

Applescript:

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


NG

Offline

 

#3 2020-05-02 04:20:45 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Make new Safari window and refer to it without ambiguity

wladdy wrote:

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:

Applescript:

tell Safari
]set w to make new window
end tell

whereas this does open a new window:

Applescript:

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.



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

Offline

 

#4 2020-05-02 04:47:21 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5233

Re: Make new Safari window and refer to it without ambiguity

Yvan Koenig wrote:

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.


Hi Yvan.

It's not related to the application "Safari" but to the term that's causing the error.


NG

Offline

 

#5 2020-05-02 06:01:40 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Make new Safari window and refer to it without ambiguity

Thank you Nigel

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

Offline

 

#6 2020-05-02 07:52:32 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Make new Safari window and refer to it without ambiguity

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:

Applescript:


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:

Applescript:


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

wladdy wrote:

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?


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).

Last edited by KniazidisR (2020-05-02 09:08:29 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)