I am trying to create a workflow to open URL from website that nags to login in when all I want is to read article which opens perfectly if in a private Safari window.
The three scripts below all work individually, but I have not been able to make them work together.
I cobbled this together by searching for AppleScript to accomplish the task.
I am unable to get script 1 to pass its information to the next. Script 2 opens a private window, but if I add script 3 to it it doesn't execute the open URL portion.
I entered a hard coded set of TextURL in script 3 as proof of concept.
Thank you for helping.
----------------------------------------------------------------
-- Script 1 Get the current URL
----------------------------------------------------------------
tell application "Safari" to return URL of front document
set textURL to text returned of the result
return textURL
----------------------------------------------------------------
-- Script 2 This opens a Private mode Safari Window
----------------------------------------------------------------
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set isRunning to is_running("Safari")
if isRunning then
tell application "Safari" to activate
delay 0.5
tell application "System Events" to keystroke "n" using {shift down, command down}
else
tell application "Safari" to activate
delay 1
tell application "System Events"
keystroke "w" using command down
keystroke "n" using {shift down, command down}
end tell
end if
----------------------------------------------------------------
-- Script 3. This will cause Safari to open the textURL
----------------------------------------------------------------
-- I would like this next statement to use the variable from script 1 above,
-- but this lets me test the script
set textURL to "https://www.apple.com"
-- end of test variable setting
tell application "Safari"
tell window 1
tell current tab
set URL to textURL
end tell
end tell
end tell