How can I use automator to make Safari open a new tab if safari is already open?

Hi.


I used applescript and automator to create shortcuts for myself for Netflix, Disney+, and Prime Video.

Here is my current applescript for opening the shortcuts, it essentially opens a new window, and then sets the url to the webpage, however, when I click on one, it opens up, but if I click on another one, it just changes the url of the current tab to whatever I inputed there. So if I open "Netflix" and then click on my "Prime Video" shortcut, it just changes that url and goes to prime video. Is there any sort of statement that would say "If safari is already open, then make a new document"?

Thank you.

MacBook Pro 13″, macOS 11.2

Posted on Feb 14, 2021 1:29 PM

Reply

Similar questions

2 replies

Feb 15, 2021 11:39 AM in response to Chauhan814

> Is there any sort of statement that would say "If safari is already open, then make a new document"?


Sure. Since you're already using AppleScript, it's just adding some logic:


tell application "System Events"
	set safariIsRunning to (exists application process "Safari")
end tell

if safariIsRunning is true then
	-- open a new window with the URL
	tell application "Safari"
		set newWin to (make new document)
		set URL of newWin to "https://www.apple.com/"
	end tell
else
	tell application "Safari"
		set URL of front document to "https://www.apple.com/"
	end tell
end if


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I use automator to make Safari open a new tab if safari is already open?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.