Open URL with Clipboard Contents in Automater

I’ve recently moved to using my MacBook a lot more for a lot of my work, from a business perspective I’ve always been a Windows users so a lot of the tools or custom tools I use or used have been Windows based only. One of the things I missed the most when moving over to macOS was the ability to quickly open certain websites and search for the data that was in my clipboard.

I regularly go into support portals and look up ticket references which can be a bit of a pain, but this gave me the ability to do CTRL+ALT+S and open that specific support portal and search for what was in my clipboard, super handy.

It’s taken me a while to get around to re-creating this on macOS, mainly because I wasn’t sure where to start! I always knew of Automater for macOS and AppleScript but I’d never used them, until today when I decided I was getting annoyed at not being able to do things as quickly as I did previously, and therefore, here is a tutorial on how to open a website from a shortcut and search for what is in your clipboard.

Getting Started

Open Automater on your macOS device and create a new document, it doesn’t matter where you select as you will eventually save it to /Users/{User}/Library/Services. You will get a pop up with a few different options, select ‘Quick Action’ then click ‘Choose’ on the bottom right.

Automater Picker Screen

Once you have chosen your workflow, on the top right you will have a few options, change “workflow receives current” to “no input”

Workflow Settings

On the left hand side in the search bar, look for “Run AppleScript” and drag it into the view on the right.

AppleScript View

This is where you need to decide what website you are going to use for your search, I use things such as ServiceNow and Snow Software Community on a daily basis, but for this example I’m just going to use Google. The code below is populated already and will work for Google, if you want to test before looking for search URLs in products that you use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
set clipboardText to the clipboard
set websiteURL to "https://www.google.com/search?q=" & clipboardText

tell application "Safari"
	activate
	if (count documents) is 0 then make new document
	tell window 1
		set tabTest to URL of tab 1
		try
			tabTest
			set current tab to (make new tab with properties {URL:websiteURL})
		on error
			set URL of tab 1 to websiteURL
		end try
	end tell
end tell

You should hopefully end up with something like the below.

AppleScript View with Contents

Go to File > Save and name the document something useful, such as “Google Search from Clipboard” in this case. Once saved, head to the Apple Icon on the top right then click on System Preferences > Keyboard > Shortcuts and you should end up in here.

Keyboard Shortcuts

Click on Services on the left and on the right, scroll all the way down to the bottom until you are under General. You should see Google Search from Clipboard here, or, whatever you named the service. You will see on the right it will say none, this means that there is currently no shortcut selected for this service, double click on none and complete the shortcut you want, so if you want Control+Command+S, you would hold these three keys down at the same time, click off and it will set the service for you.

That’s all! You might get a pop up if you’re on macOS BigSur asking you if you want Automater to be able to run commands from X application, select yes. :)

Comments beta

Join the discussion using your GitHub account here!

No comments found for this post.