---
# System prepended metadata

title: How I add an icon to the macOS Dock that just launches a URL in Safari

---

# How I add an icon to the macOS Dock that just launches a URL in Safari

<p><img src="https://hackmd.io/_uploads/rJsIQ6Y8A.gif" width="800"></p>

Using automator make an app that runs this applescript:

```applescript
on run {input, parameters}
	set targetURL to "https://example.com" -- Replace with your desired URL
	
	tell application "Safari"
		activate
		set windowList to windows
		set windowFound to false
		
		repeat with currentWindow in windowList
			if (URL of current tab of currentWindow) contains targetURL then
				set index of currentWindow to 1 -- Bring the window to the front
				set windowFound to true
				exit repeat
			end if
		end repeat
		
		if not windowFound then
			-- No window with the URL found, create a new one
			make new document with properties {URL:targetURL}
		end if
	end tell
	
	return input
end run

```

Change the URL, and save it as an application, and add that application to the dock.

_This will automatically detect a window you already have open with the URL and activate it instead._