Help in a workflow that has to recognise text in the terminal

I am trying to create a workflow in order to automate the start-up (and closing) of ytdlp, to download videos via command line. However, I don't understand how to make it recognise that [download] 100% of appears in the terminal, which would indicate that the process is finished and trigger the closing of the application. This, however, does not happen, I lack some know-how and cannot understand from the instructions on the site. See below.


Since you're typing a shell command in Terminal why don't you use KM's inbuilt action to run a shell command? You then won't need to muck about with Terminal.

Take a look at the Execute a Shell Script action in the KM wiki action:Execute a Shell Script [Keyboard Maestro Wiki] for further information.

1 Like

I admit I am a novice, I simply copied the string to the shell execution command but the macro does not activate, giving an error. Where do I go wrong?

Well, as a novice there's a lot to learn :wink:

A couple of things:

  1. The shell environment in KM is different to that in Terminal insofar as KM's shell has a bare-bones path environment set up. As a result it won't know where yt-dl is installed on your Mac. The easiest way round this is to specify the full path to yt-dl.
  2. You're not providing the video URL to the KM action.

Searching the KM forum for yt-dlp came up with this:

Take a look as it should help you. You should also study the wiki page I linked to previously as it contains important information about paths.

You might also want to search the KM forum for "YouTube" so see how others use KM to download videos.

Sorry I can't be more expansive with my help as I'm really time-constrained right now.

1 Like

Supply the full path by replacing yt-dlp with /usr/local/bin/yt-dlp.

You can check the correct path by entering which yt-dlp in the terminal.

1 Like

Path is that, but substituting it as you indicate still gives me error.

Because yt-dlp doesn't take the file path from standard input. Put the path into a variable, then use that variable in your "Execute Shell Script" action.

It's always a good idea to provide your actual macro when you've a problem, not an image of it, so that people can give you an edited (and hopefully working!) version. You haven't, so here's an example of both the error and the fix, using ls as a proxy for yt-dlp:

Shell Path Example.kmmacros (3.0 KB)


Run the macro and you'll see the first "Execute" ignores /Applications and instead lists the contents of / -- the current working directory. The second "Execute", 5 seconds later, does list /Applications because the path has been provided via the KM variable Local_path.

1 Like

I thank you. I'm starting to understand, but I still haven't managed to bypass the last test, which is to copy-paste the last element of the system clipboard after the string (I attach screen and macro). How could I do this? By creating another variable?

yt-dlp (video shell).kmmacros (1.7 KB)


Yes! Check out the section "Using Keyboard Maestro Variables" on the wiki page:

You'll want to set a new variable to text using the %Clipboard% token and then use that variable into your script, as shell scripts can't use keyboard maestro tokens directly.[]=shell&s[]=script#Using_Keyboard_Maestro_Variables

1 Like

Thank you, I succeeded! I created another empty variable that the macro goes to set just before the shell. Like this: