Youtube-dl shell script M1 Mac

I guess I wasn't a good UNIX admin because I forgot about "which." Actually I always remember what it does, I just keep forgetting that the command name is "which." It's kind of a dumb name.

Yes you can – give it a try...

It's not the same $PATH you see in the Terminal.app of course.

Many people don't have a ~/.bash_profile file, so one has to discover the correct customization file to use with source (if there is one). Unfortunately the Terminal doesn't help you do that – you have to know where to look.

I use ~/.profile myself.

@hayleyh's export PATH command is perfectly sufficient provided youtube-dl is installed in /usr/local/bin/

Since the command is not found it seems likely that u/l/b is the wrong parent directory for the command.

where is for only built-in stuff.
which for built-in OR 3rd party stuff ( think witch for magic :).

I use type myself most of the time.

-Chris

That's the issue, many a time, users who may not aware of that , trying on KM expect that PATH is the same as the one running on terminal. The reason is generally along this line "It run fine on terminal but on KM it didn't work.

By the way my youtube-dl reside in following path and this is added automatically when installing youtube-dl:

/Users/macdevign/opt/miniconda3/bin/youtube-dl

I suspect that the issue is more on PATH rather than on "/usr/local/bin" (there is a lot of "standard" paths added automatically by when we use stuff like homebrew, miniconda3).

But unfortunately unless hayleyh confirm the solutions given so far help to resolve the issue, there's no way to tell what is exactly the problem lies.

Thank you all for your thoughtful responses, this is making some sense to me now.

When I run which youtube-dl I get:

/opt/homebrew/bin/youtube-dl

Changing my shell script to this works:

export PATH=/opt/homebrew/bin:$PATH;

Changing it to these does not work for me:

source ~/.bash_profile
~/.profile

The goal for me would be to have these macros work with either path so I can use the same macros with Intel Macs as well. Sounds like I can do that by setting ENV_PATH differently on each computer, but I'm not understanding how I do that even after reading the wiki.

So you verify it in Terminal using: which youtube-dl ?

May I know if /opt/homebrew/bin is added in the $PATH variable in ~/.bash_profile ?

By the way, is $PATH in KM a empty string?

You set the path as shown with each path separated by a colon:

image

Although it's perfectly fine to have different ENV_PATHs on your different Macs, you don't have to. Including /opt/homebrew/bin in ENV_PATH on a computer that doesn't have that directory won't cause any problems. Same with /usr/local/bin.

Consider running echo $PATH on each of your machines and putting together a colon-separated string that includes all of the directories on both computers. You can set ENV_PATH to that string on both computers.

1 Like

Yeah I ran which YouTube-dl in terminal and got /opt/homebrew/bin

Being a total novice I have no idea how to answer your other questions... :grimacing: But I appreciate you trying. My way of getting around this atm will be to use a regular variable to set the path on each computer and just using that at the beginning of my shell script action.

Do as @drdrang mentions:

1- Open Keyboard Maestro > Preferences > Variables
2- Create a variable called ENV_PATH
3- Open Terminal, run echo $PATH
4- Copy-Paste the contents of echo $PATH in the ENV_PATH variable

Ok I'm back, many months later, because I want to understand what I'm doing wrong with this ENV_Path thing. I made the variable, I copied in the text from the terminal. What now? What do I write in the shell script action to call upon this variable? What replaces "export PATH=/usr/local/bin:$PATH;" in my original screenshot?

The name Needs to be All caps.

youtube-dl -F yoururlhere

If you created the ENV_PATH variable, you don’t need to add that line in your script. You can remove that line.

Thanks!!!

1 Like

See this:

Path in Shell Scripts

1 Like

Hi there, so I've been setting up a simple script to run at the beginning of my macros to ensure the ENV_Path variable is set correctly on whatever computer I set up the macros on, it looks like this:

Normally it does the trick, but on an M1 MacBook Pro I recently got this:
/usr/bin /bin /usr/sbin /sbin

Which didn't work, so I tried it in terminal and got this result which when I put it into my ENV_Path manually worked just fine:
/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

How do I ensure that I'm getting an accurate result here? I'm trying to make this setup as simple as possible as I'm looking to share these macros.

What you are trying to echo here is the path that is set in the ENV_PATH variable. (As this is the path that is known to KM.)

That's the whole point of that variable. If KM used the path from the interactive shell, you wouldn't need to set ENV_PATH.

Unless this is entirely different on Apple silicon… (I am still on Intel Macs.)

Ok I see, so is there a way to retrieve the path from the interactive shell without manually copying and pasting it in?

Hello @hayleyh :wave:

Don’t do this :see_no_evil::see_no_evil::see_no_evil::see_no_evil::see_no_evil::see_no_evil:
Especially when you’re syncing your macros… if you want to use this approach- it will be better to turn off syncing.

If you want to switch between different $PATH Setups - your best chance is that you use the ~/.profile / ~/.bash_profile approach with the source command like @macdevign_mac & @ccstone talked about. Doing this you have the ability of manipulation in your $PATH on every machine like you need it for each particular use cases - and you don’t ever need to set ENV_PATH for Keyboard Maestro BUT you’ll have to use the absolutely same basics for the dotfiles setup and handling on each machine - regardless of the exact amount of $PATH configuration in detail.

If you just want the Variable - without using the dotfiles - @drdrang has you covered. He mentioned the right way to put two different ENV_PATH Values together in post #10. But this approach will need your time whenever you are changing the $PATH on either one or more Macs. Using this approach you can set the ENV_PATH Variable but here is one caveat you have to be aware of … the right order is very important.

Edit:
If you use both - Intel based Macs and Apple Silicon based ones - either approach will work when your macros are in sync as if there were only Intel based Macs or the Apple Silicon ones.

Greetings from Germany

Tobias

Well, you could copy it automatically then: Make a macro that looks for the path string in the file you consider the file with the "correct" path in it (e.g. .zshrc or whatever) and saves it to your ENV_PATH var.

But somehow I don't really understand the problem. Unless you have dozens of Macs, it shouldn't be too time-consuming to set Keyboard Maestro's ENV_PATH on each machine.

This is something you do once in the life of a Mac, or at max once or twice more (as in your case, if you want to add an extra path for a program, or if, for example, the path used by your package manager has changed, or you start using a different package manager).

And don't forget, for special paths that are only used by one thing, you can always explicitly set it in the macro where you need it, without touching the ENV_PATH. (You can also make this conditional, depending on the type of Mac, so you can sync the macros.)

Btw, if you're looking for a more global path source, /private/etc/paths or /private/etc/paths.d/ doesn't work for this.

Hello Tom :wave:

Thanks about this little reminder - totally forgot about that possibility … I’ve corrected my post above :arrow_up: since I somehow messed it up before posting and saw your reply.

If you wanted to go really crazy on using different $PATH configurations without combining them to one with sync enabled there is also a way for sure - but every macro that uses the ENV_PATH Variable needs know if it can use the setup for the particular Mac first and then you’ll have make sure that every other Macro is paused until the ENV_PATH could be set to the Value that is needed.

But this is a cumbersome way that would need to be configured absolutely reliable… and it is not really a timesaver if you work with more than one machine simultaneously and two would have to wait for the third one has finishes its operation so that the Variable could then be set to another $PATH.

If you would like to know about what goes on on each machine because everything thing is in a chain - then I this maybe makes more sense but I would say ONLY for debugging purposes.

I hope this makes sense in some kind of way because I don’t really want to go into much more detail about this.

I think @hayleyh now has mute than enough information - and needs to decide which kind of setup makes more sense for his/her use case.

Anyway - I’m out for today …

Greetings from Germany

Tobias

Thanks for the detailed responses. My goal isn't to sync between dozens of macs, it's to share the macros I made with others and have them just work without having to explain how to get the path from the terminal and input that into KM. Homebrew seems to be installed in different places depending on the mac. I've tried creating a catch all that would work no matter which mac but in my testing with the computers I have access to it hasn't worked, it seems it works only when I match the exact output from the terminal for that computer.

My background is video editing, I have a very vague understanding of what any of this path stuff actually is and the people I'm trying to share my macro with have even less. If I have to prompt them as part of the setup of my macro to fill out the ENV_PATH variable manually then so be it but I would prefer to avoid adding complex steps into this setup.

Truly my ideal setup would be for the macro to install homebrew, yt-dlp, and ffmpeg automatically when the macro first runs, but I can't figure out how to do something that complex so I'm already going to have to write up a guide on how to install those things to people who have likely never used the terminal before... hence my hope that I could just use KM to grab whatever it can for stuff like this.

Hopefully that clarifies my use case a bit more. Thanks again for your responses.

Okay, just realized a dumb error on my part. During my testing I couldn't create a working catch all ENV_PATH variable because I was setting the variable ENV_Path not ENV_PATH. Setting ENV_Path APPEARED to change the ENV_PATH variable but clearly there is a distinction because it would not run my scripts when I set the variable this way. This is a weirdly invisible distinction in KM, but all good now. Hoping I can eliminate the need to set a distinct ENV_PATH on each computer now.