When I find things I enjoy watching on YouTube, sometimes I want to download them—because they may go away, or I may want to watch offline. There are any number of tools out there that will do this for you, including web sites and Mac-specific apps. On the Mac side, I had been using 4K Video Downloader, but recently found VIDL, which had one big advantage for me: It comes with a Safari toolbar icon.
When I see a video I want to keep, I click the VIDL toolbar button, and VIDL launches and downloads the video. (Because it's based on the open source youtube-dl, VIDL supports a lot more sites than does 4K Video Downloader, which is also nice.)
But recently, I noticed that some of the videos I downloaded with VIDL were at 640x360 resolution, even though the source on YouTube was at least 1920x1080. I tried those same URLs in 4K Video Downloader, and I was able to download the full HD versions. There aren't many settings in VIDL, so I didn't see any obvious way to force it to get higher resolution versions1youtube-dl is supposed to get the highest-resolution version automatically, so I switched back to 4K Video Downloader…but I really missed the handy toolbar button.
It's not like it was a lot of work to copy a URL, switch to 4K Video Downloader, and paste, but it was just enough work to get annoying. If I had the skills, writing a basic extension like this for Safari should be pretty simple. But as I don't have the skills, I went looking for another solution, and I found one using Automator:
I created a new Service in Automator that sends URLs to 4K Video Downloader via the contextual menu in Safari's URL bar.
The Automator service itself is really basic: It works on the selected URL in Safari, copies it, launches (or switches to) 4K Video Downloader, pauses for a second to make sure the app is ready, and then pastes the URL, which is actually the only tricky bit. The final service looks like this:
The only tricky part was figuring out how tell 4K Video Downloader to paste the link, so it would start downloading. I tried sending it the Command-V keystroke, which is defined as a shortcut in its menus. While this worked when I tested it in Automator, it didn't work when I saved the app—perhaps because AppleScripts need permission to send keystrokes.
Instead of granting permission (which I'm not even sure would work with a service versus an AppleScript app), I chose to use GUI scripting to actually select the Paste menu item, which is what that ugly code does in the final step. It's not pretty, but it works. If you'd like to use this for yourself, or modify it to work with other download apps, feel free to download the service. In theory, it should "just work" if you drop it into your user's Library > Services folder.
It's a little timesaver, but I've already gotten used to right-clicking on a video's URL to quickly save it for future viewing.