Saving Safari window Ids to close windows
Saving Safari window Ids to close windows
- Subject: Saving Safari window Ids to close windows
- From: "@lbutlr via AppleScript-Users" <email@hidden>
- Date: Sun, 6 Sep 2020 08:21:04 -0600
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.
--
This magic gin better make us see unicorns that fart rainbows.
_______________________________________________
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