YouTube-dl Macro (v9.0.1)

YouTube-dl Macro (v9.0.1)

I want to get km to paste a YT URL once I hit OK. Can someone tell me what I'm doing wrong?

Try removing the penultimate action (you could actually just remove the last two actions as a notification seems a bit redundant), and try:

youtube-dl -f mp4 %Variable%Path%

as the text to be pasted in the second, which would also be the last, action.

1 Like

I got it to work. Thank you!

You can also set a default location for downloading the YouTube video using the -o option in youtube-dl (see man youtube-dl).

youtube-dl -f mp4 %Variable%Path% -o '~/Movies/YT/%(title)s.%(ext)s'

This saves the file in a subfolder of my user's Movies directory, using the youtube title of the movie and, in this case, an mp4 extension. You can build relatively complex naming schemes with the templating language in youtube-dl if you want.


Nice tips on the argument specification. However, you replied to the wrong person (I don’t use that program). In this instance, the only other person is the OP, who I think should get notified of all replies. However, were that not the case, say, in a future thread where you wished your response to be noticed by a specific individual in that same thread, you would need to use the reply button under their message, or tag their name intentionally with a @.

I assume we’re dealing with this program being called (ultimately) from the command line in a bash shell, in which case you need to mind your quotes. The path you supplied as the parameter for your -o option almost certainly won’t exist, as the shell doesn’t expand the tilde inside single- or double-quotes. I can’t advise how youtube-dl handles its own substitutions within single- versus double-quotes, so I’ll let you double-check that, but the remedy to utilise the tilde in the way I believe you intended is to move it outside the quotes like this:

youtube-dl -f mp4 %Variable%Path% -o ~/'Movies/YT/%(title)s.%(ext)s'

Alternatively, you can use double-quotes and the shell variable containing the user home directory path:

youtube-dl -f mp4 %Variable%Path% -o "$HOME/Movies/YT/%(title)s.%(ext)s"

Strictly speaking, I ought to have enclosed the KM token inside double quotes as good practice, and in case the URL contains any characters with specific meaning inside the shell:

youtube-dl -f mp4 "%Variable%Path%" -o "$HOME/Movies/YT/%(title)s.%(ext)s"

One last consideration is, given we’ve been constructing this shell command in the context of a Keyboard Maestro text field that undergoes token processing (thus replacing %Variable%Path% with its value), I cant recall off the top of my head what would happen during this processing at around the occurrences of the two additional % delimiters: assuming the variable named "(title)s." doesn’t exist in KM (if that’s a valid variable name, which it may very well be), then my feeling is the processing should leave the rest alone, but there’s an outside chance the percent symbols are stripped unless they’re doubled up (I can’t check myself – computer is broken).

Thanks for your reply @CJK. Replying to the original poster now. youtube-dl seems to do the substitution just fine with the single quotes, at least in iTerm using a zsh shell. I followed the suggestions from the man page and thus far it has worked for me. Good point though that this could be a problem if KM has the youtube-dl substitution tokens as KM variables.

Ah, so the youtube-dl program itself will happily handle the tilde expansion ? Or is it zsh that has different rules about what it does or doesn’t expand inside quotes ?

From reading the man page discussion on output templates, youtube-dl does the expansion using python string formatting operations. I think having the template output text in single quotes prevents the shell from doing its own expansion prior to youtube-dl doing its magic. I don't think it matters whether it's a zsh shell or a bash shell.

1 Like

Actually, I just entered the same command in a bash shell with the same result.

That's pretty cool.

Hey Norm,

This fails to produce a title for me in the Finder:

youtube-dl -f mp4 '' -o '~/Downloads/YT/%(title)s.%(ext)s'

Playing around with the quotes doesn't make a difference.

Any idea why?



Can you please clarify? What do you mean fails to produce a title? Does it say couldn't extract title or something?

The title I get in the Finder is:


Full path:



Not really sure. It worked for me.

I downloaded youtube-dl from homebrew. The version info is:

 $   brew info youtube-dl
youtube-dl: stable 2019.08.13, HEAD
Download YouTube videos from the command-line
/usr/local/Cellar/youtube-dl/2019.08.13 (12 files, 2.1MB) *
  Built from source on 2019-08-27 at 19:59:08
==> Options
	Install HEAD version

How did you install youtube-dl?


Can someone help me with this yt-dl command: youtube-dl -f mp4 -o "/Users/me/Downloads" URL

What is wrong with me changing the download folder? The error I get is "unable to open for writing: [Errno 21] Is a directory: "

From this discussion thread, it would appear you need to specify a file path as the output, which cannot be a folder path. You're basically asking it to save the file as ~/Downloads, which, if it were go ahead and do that, would overwrite your entire downloads folder and replace it with a song I can't imagine is so amazing it would be worth the sacrifice.

Hey Norm,

Using MacPorts.

youtube-dl --version
--> 2019.07.16

I see this is a bit older than the Homebrew version.

Okay, I uninstalled the MacPorts exe and installed the HB exe – and this seems to have fixed the problem.



Both MacPorts and Homebrew now have v2019.09.01

I confirm that both work correctly on my macOS 10.12.6 (Sierra) system.


Glad the updated version worked. Thanks for the update!


1 Like

When executing the youtube-dl command in a terminal it gives you a nice download progress indication that updates until it reaches 100%

[download] 100% of 19.86MiB in 05:10

When I execute the same thing in KM using the Execute Shell Script action, I lose this progress indication and I don't know when the D/L is complete until the KM macro finishes. It would be nice to be able to get some idea that the D/L is happening and that the D/L is not hung. Any idea on how to do this?