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.
I've done something similar with Keyboard Maestro and youtube-dl installed with Homebrew. I grab the front Safari window, check to make sure it has YouTube open, strip out the YouTube video id, and pipe that to youtube-dl to download the file to my drive. It has worked great. This approach also allows me to use youtube-dl options to customize quality settings, etc.
I may try that, too, given that VIDL seems to be passing wrong info to youtube-dl.
thx;
-rob.
Let me know if you want the macro, I can send it to you. I don't see a way of posting it on your site. I tried posting the text of the macro using Keyboard Maestro "Copy as Text" and got a warning about it being potentially unsafe.
Seems that https://robservatory.com/dlfiles/4k_download.workflow.zip is a broken link. I got "Nothing Found"
Turns out it works much better without a typo—try again now. Sorry about that, and thanks for catching it!
-rob.
Thanks, works fine now.
I created the service using your screenshot. Can you help me with this"
The action “Run AppleScript” encountered an error: “System Events got an error: com.automator.runner.xpc is not allowed assistive access.”
In Catalina, you'll need to grant permissions in Sys Prefs > Security & Privacy > Accessibility to both AEServer and Safari; it should work then (at least, it did in my testing here).
-rob.
I'm composing this for the 2nd time, because I somehow lost track of the first version of this reply.
I'm old now, so there's not the slightest reason for me to try to cover up my inadequacies or to pretend I'm more capable than I am. Here's a problem I've had to deal with for my entire life. I seem to be smart enought to want stuff, but not smart enough to figure out how to get said stuff.
After reading your reply, I seem to have found a way to work around the problem I mentioned in my original post, so I'm going to try to describe how I arrived at the solution in case anybody else finds themselves in the same situation. I don't seem to be able to remember every detail or to reverse my steps adroitly enough to recover those details, so if you can fill in any gaps, you are most welcomed to do so.
I knew it shouldn't be any problem to add Safari to Accessibility, so I just unlocked the Security & Privacy prefpane (I'm using Mojave), and dragged the Safari application icon in there. That was enough to finish that part.
But figuring out how to add AEServer presented a more difficult problem because there doesn't appear to be file system object named "AEServer" or even containing "AEServer" as part of the name. So I searched DuckDuckGo for "grant accessibility to AEServer macOS". I eventually found a Terminal command to accomplish that action:
defaults write /Library/Preferences/com.apple.AEServer RestrictAccessToUserSession -bool false
In going back through my browser history to compose this reply, I don't seem to be able to find the exact search result that included the suggestion to run that command. I'm quite frustrated to have to report that. If you can provide the information, please do.
I ran that command in Terminal, but it wasn't successful, and the result was:
"Could not write domain /Library/Preferences/com.apple.AEServer; exiting".
So I ran it again, prefacing the command with "sudo ":
sudo defaults write /Library/Preferences/com.apple.AEServer RestrictAccessToUserSession -bool false
That command appeared to be completed successfully, and, after quitting all open applications so that I could be as sure as possible that the necessary ones would get their required restart, I launched Safari and opened an new YouTube location, and this time the Service worked.
Thanks.
On my Mojave install (which is what I use most of the time), I didn't have to grant access to AEServer—it's not listed in Accessibility in my system at all.
Very weird.
-rob.
I also use 4K Video Downloader, and went through the exact same thought process as you a few weeks ago! I thought, it's not much hassle, but this could be easier. I already use FastScripts (by Red Sweater Software), so chose to write a simple AppleScript which I put in the FastScripts menu and assigned the shortcut ?4. Here's the script in case it's of use to anyone (you have to add FastScripts to the "Allow" list in "Accessibility" in the "Security & Privacy" system preference for this to work):
tell application "Safari"
set vURL to (URL of current tab of front window)
set the clipboard to vURL
end tell
tell application "4K Video Downloader"
activate
tell application "System Events" to keystroke "v" using command down
end tell
"?4" above seems to be the comment system not liking Unicode :-( . I assigned this script ctrl-4 as a shortcut, so I just hit that to send the current page I'm on to 4K Video Downloader. I should say that with a bit more time, I'd put some error checking code in the script to only work when the URL has a youtube.com domain, but it wasn't worth the time for my usage.
Yes, FastScripts by Daniel Jalkut, Red Sweater Software, is a very fine application. I highly recommend it.
Not something I do but thought I might and remembered your post. Just read https://medium.com/better-programming/impress-your-friends-with-these-fun-and-useful-mac-terminal-commands-c091ec2a0024 and it's two lines (and of course if you do it all the time an alias would make it even faster)—one to install and one to download.
brew install youtube-dl
youtube-dl "video-url"
Guess I can't edit my post, but on reread, not sure if this addresses the 4K issue.
Yea, that was my main problem. From reading the first comment, it seems I could make youtube-dl do some parsing to get the highest quality version, but I haven't spent any time on that yet.
-rob.
Have you ever looked at Downie? Available via Setapp and direct purchase, has extensions for most browsers as well as a URL scheme for making bookmarklets. Wide site support, great interface, and even (optional) automatic conversions to mp4 when needed.
I haven't, I'll check it out—thanks for the pointer!
-rob.
Excellent. I have a similar workflow, but how to tell automator to take a list of links from a text file? I know youtube-dl can do this but it does not work and want to have it with automator. Thanks!
I haven't done a ton with Automator, at least not in many years. But I thought there was a way to pass it a list of things; sorry I don't have better info.
-rob.
Comments are closed.