MacStories Starter Pack: Clean URLs and Remove Tracking Parameters with URL Cleaner

Editor’s note: Clean URLs and Remove Tracking Parameters with URL Cleaner is part of the MacStories Starter Pack, a collection of ready-to-use shortcuts, apps, workflows, and more we’ve created for help you get the most out of your Mac, iPhone and iPad.

Imagine this:

You’ve just come across an interesting article or product that you want to share with someone, so you copy the URL and you’re ready to send it to iMessage, tweet it, link it on your site – you call. Then you notice that the URL has a bunch of ugly tracking parameters appended to the end. I’m sure you’ve seen them too: they’re the ones ?utm and soc_src1 and similar text strings that some web publishers rely on to monitor where traffic is coming from and track other metrics about URLs clicked. For a publisher, these data elements can actually be useful; For the end user, however, I’ve always wished there was an easy way for apps or extensions to “clean up” URLs and return the vanilla version of a link without any tracking parameters attached.

So for the start of our MacStories Pack event, I decided to fix it myself with a shortcut that I called appropriately URL Cleaner. With this shortcut, which you can download for free at the end of the story and find in the MacStories Shortcuts Archive, you’ll be able to instantly remove popular tracking parameters from any URL and get a “clean” version copied to the system clipboard. Even better, URL Cleaner has been specifically optimized for iOS, iPadOS, and macOS, taking advantage of desktop-specific actions in macOS Monterey while remaining integrated with the Share Sheet and Siri on iPhone and iPad.

We’ll take a look.

Behind the scenes of the URL cleaner

First, I should thank a MacStories friend and developer Robb Knightwhich released an app called TrackerZapper few months ago. TrackerZapper is a free utility that sits in your Mac’s menu bar and removes tracking settings from links you copy. Given that TrackerZapper is open source, I was wondering if I could turn its core functionality into a shortcut that works on all platforms where the Shortcuts app is available. So, courtesy of Robb, I was able to take TrackerZapper’s built-in list of well-known tracking parameters, extend it with a few additions, and turn it into a regular expression for hotkeys that quickly removes all matching parameters URLs.

I designed URL Cleaner to be used in different ways. At its most basic level, you can manually run the URL Cleaner in the Shortcuts app or from the Home Screen widget on iOS/iPadOS. In this case, the shortcut will try to find a URL that you have already copied to the clipboard. If no URL is found, you will be prompted to enter one manually. The latter option is most useful on macOS, where you may have copied a URL to the clipboard a while ago, so it’s no longer the most recent item in your clipboard history. , but you can still access it with a clipboard manager (I’ve tried Raycast for that recentlyand I like it).

URL Cleaner can also receive an input URL from the Share Sheet (on iPhone or iPad) or another shortcut, which means you can use URL Cleaner like headless, function of inserting other shortcuts. If you often deal with URLs in your shortcuts and want to make sure they are always “clean” URLs without tracking parameters, here’s what you can do: in your shortcut, use the action “Run Shortcut” and select the URL. Cleaner as a shortcut you want to run as a function; then make sure the input for this action is the URL you want to clean. When the shortcut runs, it will call URL Cleaner in the background, which will process the URL, copy a cleaned version of it to the clipboard, and output it back to the original shortcut. I’ve started using URL Cleaner as a function in dozens of my shortcuts, and I love it.

I also want to highlight how I optimized URL Cleaner for macOS Monterey with a new technique that brings extra intelligence to shortcuts.

On Monterey, Shortcuts offers an action called “Get Safari’s Current URL” which can read the URL of the currently active Safari tab. I wanted to use this action so you can trigger URL Cleaner from the menu bar or with a hotkey to clean up the currently open Safari tab URL. The problem is that the action fails if a) Safari is closed or b) you’re not using Safari as your Mac browser to begin with. To work around the problem while maintaining the convenience of this action, I added an AppleScript step that checks if Safari is open or not. if so, the shortcut performs the “Get Safari’s Current URL” action; otherwise it ignores the Safari action and tries to fetch the URLs with the methods I described above.

I plan to explore this technique in more depth in the next Automation Academy lesson for MacStories Plus and Premier Club Members, which will cover advanced tips and techniques for shortcuts on macOS Monterey. Essentially, Shortcuts for Mac doesn’t have a built-in action to check if a particular app is running. as AppleScript can do, it was easy enough to drop in a script that checks Safari’s state and returns a response.

Regardless of how you launch URL Cleaner, the end result will always be the same: you’ll receive a notification that displays the cleaned URL, which will also be copied to the clipboard so you can paste it elsewhere.

I should also note that, if you want, you can modify URL Cleaner by adding more tracking parameters that need to be stripped from URLs. To add more parameters to the default URL Cleaner list, just enter a single character pipe | and the tracking parameter you want to remove in the “Text” action at the beginning of the shortcut as shown below. You can repeat this process with as many parameters as you want and the URL cleaner will still run in seconds.

So that’s the URL cleaner. This is a really useful shortcut that I’ve been using for a few weeks, both as a standalone utility and as part of other shortcuts as a function that I can run in the background. It seemed appropriate to share URL Cleaner as the first shortcut for the MacStories Starter Pack, but stay tuned: I have a lot more to share throughout the week.

You can follow the MacStories Starter Pack on our hub, or subscribe to the dedicated Starter Pack RSS feed.

Comments are closed.