(Old) Issue with Shell, still can't figure out why this isn't working

For some reason I never got to reply to your message. I must have skipped the notification.
When I tried to install ffmpeg, that was the option that was offered to me. I have no idea how packages and managers work, so I just did what I saw online.

I believe I have brew installed, but since I'm still on Catalina and it doesn't support brew, I always get errors when I try to install a new package

brew folder

image

I remember at one point in the past where I tried using a variable without quotes, the original path or whatever I was using, didn't have spaces, but it didn't work. Only worked with quotes, hence my statement. I can't recall what it was, though.

In your .zshrc file, this:

        export PATH="/opt/anaconda3/bin:$PATH"

and these:

# ImageMagick path
export MAGICK_HOME="/usr/local/ImageMagick-7.0.10"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

...are setting your Terminal session's PATH and the DYLD_LIBRARY_PATH environment variable -- that isn't happening in your "Execute Shell Script" action.

For a test, try including them in the action's script:

#!/bin/bash
export PATH="/opt/anaconda3/bin:$PATH"
export MAGICK_HOME="/usr/local/ImageMagick-7.0.10"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

magick "$KMVAR_Local__VarName" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB "$KMVAR_Local__parentPath"-optimized.jpg

...and see what happens.

1 Like

That worked! Thanks! :raised_hands:

I guess that for ImageMagick I don't need the first line:
export PATH="/opt/anaconda3/bin:$PATH"

So is there a way to make it so when I use the Execute Shell action I don't have to think about all of these "tricks" and just use the command the same way as I use it in Terminal?

I can save this to use with ImageMagick, but if in the future I add another package, then I have to keep asking for help. Is there something I can do?

By the way, for the ffmpeg command I always have it set like this as a favorite action:
image

That's the one I would add to KM's ENV_PATH -- if you're installing more packages with Anaconda you may need it. It isn't the individual packages that are the problem -- as you've seen with ffmpeg you can "target" them on the command line -- but if those packages reference other packages that Anaconda has installed then they'll need to know where to look.

I'd keep the ImageMagick ones out though, and set up a favourite "magick" action that included those 3 lines at the top of the script. A clean PATH is a happy PATH, and the less that's in there the less you have to sort through when things go pants!

Here?
/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

Any suggestion on how that path "should" look like in terms of the order of the paths, including anaconda?

As I mentioned, I'm not familiar with how the packages work and all that, and when I see something online they always mention brew anyway. Now the issue, as I also mentioned, is that I can't seem to rely on brew to install anything, because it always stalls at one point. Today I had to install ImageMagick "manually".

I installed other packages via pip (I guess that's another package manager or something?). At least the instructions that I was given, mentioned installing via pip.

For me this is all a big mess and it annoys me when I don't understand these things... along with the issue of brew not working on my macOS.

So something like this
image

For ffmpeg I don't mind it like this, as I have a favorite action anyway
image

But if I can set the ENV_PATH properly and avoid having the path /opt/anaconda3/bin in the action, why not?

Yes. PATH is checked in order, stopping on first match. So when you use ls the shell goes

  1. Can something named ls be found under /usr/local/bin? No. So...
  2. Can something named ls be found under /opt? No. So...
  3. Can something named ls be found under /usr/bin? No. So...
  4. Can something named ls be found under /bin? Yes! Run it.

So you generally want your "special paths" at the front of the list so you can override any defaults. In this case:

/opt/anaconda3/bin:/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

...and remember that that would mean that if you install the same-named utility with both Anaconda and Homebrew then the Anaconda one would be used.

Assuming MAGICKHERE is placeholder for your magick comand, then yes. If it is then I'd avoid accidents by making it a comment instead:

#!/bin/bash
export MAGICK_HOME="/usr/local/ImageMagick-7.0.10"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

# magick command goes here

Bang on. And it also would mean that when you updated to anaconda4 or got an Apple Silicon machine and started using brew's ImageMagick instead you would have to go through and change all your actions -- you'd just update ENV_PATH.

Similarly, do watch out for any update to ImageMagick since we have hardcoded the version number into the action...

I see. Thank you. I will try that new PATH then.

Yes I usually use capitalized text for things I will just double click and paste something else. The same for my favorite action for ffmpeg:
image

It's just a "system" I have for a lot of stuff, in and out of KM.

Makes perfect sense, yes.

True. Can I just rename the folder and then rename the action? Or is there anything that I need to change? When I was installing it today, I know I had to do a lot of things in Terminal to update the library files or something like that... Do you think there's something "internally" that I would have to change via Terminal if I rename the folder to just ImageMagick?

I created 2 actions to test this
image

With ENV_PATH set to
/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

It displays the ffmpeg information in a window when I run the green action.

When I change the ENV_PATH to
/opt/anaconda3/bin:/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

and I run the red action, I get this:
2024-08-27 12:41:40 Action 16033924 failed: Execute a Shell Script failed with script error: text-script: line 1: ffmpeg: command not found

That's why it's so confusing to me, because everything you said makes perfect sense, but then it doesn't work.

It looks like you're doing everything right, so the problem isn't with you!

Posting the dialogs from this may reveal something:

ffmpeg Troubleshooting.kmmacros (3.1 KB)

I've always avoided Anaconda myself, since I spend a lot of time at work fixing problems it's caused -- though that's more likely down to our scientists doing it wrong than Anaconda itself :wink: If you can remind me which version of macOS you're on I see if I can find a test machine.

First action:
/opt/anaconda3/bin:/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

Second action:
Runs, but no window pops up

Don't know if this is the same thing, but if I run "which ffmpeg" in Terminal, I get this:
(base) dannywyatt@Dannys-MacBook-Pro ~ % which ffmpeg
/opt/anaconda3/bin/ffmpeg

macOS 10.15.7 (Catalina)

Is there a way to stop using ffmpeg with anaconda without causing any issues?
Today I installed MacPorts when I was trying to make ImageMagick work so maybe I can use that to reinstall ffmpeg (and any other packages that maybe anaconda installed?)

I just don't want to make changes that will then mess with any macros I have or any configurations that make ffmpeg work at the moment. Since I don't know anything about these things, I don't know how this works and if making changes would break anything?

I asked ChatGPT if I could install ffmpeg via MacPorts and it said yes, I just need to be careful about the PATH and all that. So, without knowing much about this, here's what I would like to know:
What if I install ffmpeg and any packages I remember installing such as ffmpeg-normalize via MacPorts, then "disable" the PATH for anaconda (in the zshrc and bashprofile files, maybe?), but leave it installed just in case something breaks in the future, and just update the path for ffmpeg and ffmpeg-normalize to use mac ports? Hope it makes sense...?

That way I can start using something that apparently could be more reliable, without uninstalling anaconda, which will be there in case I notice something not working that relies on anaconda. Does it make sense?

Ok, I installed ffmpeg via MacPorts, did everything that ChatGPT told me to do, updated the .zshrc file to

#MacPorts path
export PATH="/opt/local/bin:$PATH"

homebrew path
export PATH="/usr/local/Homebrew/bin:$PATH"

homebrew shell environment
eval "$(/usr/local/Homebrew/bin/brew shellenv)"

imagemagick path
export MAGICK_HOME="/usr/local/ImageMagick-7.0.10"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

The ENV_PATH is set to

/opt/local/bin:/usr/local/bin:/opt:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

When I run which ffmpeg in Terminal I get this:
/opt/local/bin/ffmpeg

When I run a simple command in Execute Shell:

ffmpeg -i "/Users/dannywyatt/My Files/Inbox Global/Untitled.wav" "/Users/dannywyatt/My Files/Inbox Global/Untitled.mp3"

I get:
Action 16240278 failed: Execute a Shell Script failed with script error: text-script: line 1: ffmpeg: command not found

So I got back to adding the path to make it work (which in that case, it doesn't make any difference if it's MacPorts or Anaconda)

/opt/local/bin/ffmpeg -i "/Users/dannywyatt/My Files/Inbox Global/Untitled.wav" "/Users/dannywyatt/My Files/Inbox Global/Untitled.mp3"

I just don't understand what's the issue with Keyboard Maestro, if Terminal works as expected...

You've tried comparing the outputs of:

which ffmpeg

from, respectively:

  1. the environment in your copy of Terminal.app, and
  2. the particular Execute Shell Script environment which you are building up in Keyboard Maestro.app ?
1 Like

Terminal:
/opt/local/bin/ffmpeg

Keyboard Maestro
Shows the same path, but I had to set it to "Include All Variables", otherwise it would show me this in the Engine.log:
Task failed with status 1

Why is that, if I'm not using KM variables? :thinking:

If I run this in Terminal, it works (without adding the full path):
ffmpeg -i song.wav -vn -ar 44100 -ac 2 -b:a 192k song.mp3

If I run the exact same command in Keyboard Maestro set to "Include All Variables", it also works.

But if I set to "Include No Variables" I get this:
Action 16240720 failed: Execute a Shell Script failed with script error: text-script: line 1: ffmpeg: command not found

You are not using ENV_PATH ?


Execute a Shell Script :: ENV_PATH [Keyboard Maestro Wiki]


If you set a blanket "Include No Variables", without checking any exceptions in the list below, then your environment definition collapses because you have hidden the Keyboard Maestro variable ENV_PATH.

If you want no other KM variables in the shell environment, then the trick is to check just ENV_PATH for inclusion.

2 Likes

Oh you're right, I wasn't thinking about the ENV_PATH.
I just included it and it's now working! :slight_smile:
I will change my shell action that's saved as favorite to include this.
Really appreciate your help on this! :raised_hands:

1 Like

Nice catch, @ComplexPoint -- the tester here does, of course, "Include All Variables".

One to remember for the future...

2 Likes

I wonder whether @peternlewis (or any other Wiki maintainers) feel that the Wiki section which says that:

Once the ENV_PATH variable is set, it will remain in your Keyboard Maestro variable until/unless you delete it, and remain available to every Execute a Shell Script action that you might use in the future.

(See: Path in Shell Script)

might benefit from a caveat about the Include No Variables option
(in Execute Shell Script) actions ?

Done.

2 Likes