Re: Saving Safari window Ids to close windows
Re: Saving Safari window Ids to close windows
- Subject: Re: Saving Safari window Ids to close windows
- From: Yvan KOENIG via AppleScript-Users <email@hidden>
- Date: Sun, 6 Sep 2020 17:31:29 +0200
As far as I know, a window hasn't an URL property.
The dictionary states:
document n [see also Standard Suite
<applewebdata://EF8C1731-FAB5-46C8-A9E3-596BAF27B966#Standard-Suite.document>]
: A Safari document representing the active tab in a window.
properties
source (text, r/o) : The HTML source of the web page currently loaded in the
document.
URL (text) : The current URL of the document.
text (text, r/o) : The text of the web page currently loaded in the document.
Modifications to text aren't reflected on the web page.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche
6 septembre 2020 17:30:42
> Le 6 sept. 2020 à 16:21, @lbutlr via AppleScript-Users
> <email@hidden> a écrit :
>
> So, I've been experimineting with Safari and AppleScript and I had this code
> that is intended to open a window, open a window, open a window, close the
> first window, open a window, close the second window, and finally open.
> window.
>
> Now, in this case I am testing with just opening a single window, but
> eventually this will be opening specific windows, some of which I just need
> to be open for long enough for the page to have loaded fully, but I cannot
> get the id to save properly or I don't know how to access it properly so that
> I can then go and close the window I want.
>
> #v+
> set theURL to "https://localhost/"
>
> j = 0
> repeat 5 times
> set j to j + 1
> set myID to {}
>
> tell application "Safari" to make new document
> delay 0.1
> -- Does not work if Safari doesn't already have a window?
> -- Assuming this is the only way to get private window
> tell application "System Events" to tell its application process "Safari" to
> keystroke "N" using {shift down, command down}
> delay 0.1
> tell application "Safari"
> activate
> copy id of window 1 to the end of myID
> set URL of front window to theURL
> if j > 2 then
> set TwoOld to j - 2
> set thisID to item TwoOld of myID
> tell (every window whose id is thisID) to close
> end if
> end tell
> delay 1
> end repeat
> #v-
>
> Obviously, I would also like to be able to "set URL of front window to item j
> of theURL" but I haven't gotten that far. Other than it didn't work.
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden