You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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
Question marked as Top-ranking reply

Posted on Feb 15, 2021 11:39 AM

> 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


Similar questions

2 replies
Question marked as Top-ranking reply

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


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.