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

I installed ffmpeg and every time I have to use it inside KM I always have to add this to the beginning of the script:

I already have this in my variables:

Initially, from what I was told, this would fix the issue and I would just have to add the script, like this, for example:

ffmpeg -f avfoundation -i ":3" -t 3 /Users/dannywyatt/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/Tiago/System/Attachment\ Files/audio/audioaudiocapture.mp3

But to make it run in KM, I have to have this:

/opt/anaconda3/bin/ffmpeg -f avfoundation -i ":3" -t 3 /Users/dannywyatt/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/Tiago/System/Attachment\ Files/audio/audioaudiocapture.mp3

So this is the first issue, if someone can help me with this?
I'm not an expert, but this seems to be the issue with certain workflows, for example if I want to use different variables to create a final script and then merge everything into a single variable and just add $KMVAR_Local__myVarHere to the Execute Shell action, it doesn't work, even though the whole script is working when I paste it directly to the Execute Shell action.

So, this does NOT work:

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

This DOES work:

This does NOT work:

2024-05-26 09:50:43 Action 15907120 failed: Execute a Shell Script failed with script error: ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
  built with clang version 11.1.0
  configuration: --prefix=/opt/anaconda3 --cc=x86_64-apple-darwin13.4.0-clang --disable-doc --disable-openssl --enable-avresample --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-libx264 --enable-pic --enable-pthreads --enable-shared --enable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/Users/runner/miniforge3/conda-bld/ffmpeg_1627813741069/_build_env/bin/pkg-config
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[AVFoundation indev @ 0x7fb94c704280] Video device not found
":3": Input/output error

If I save this code to an .sh file and try to read it:

Execute a Shell Script failed with script error: /bin/sh: /Users/dannywyatt/My Files/AppleScript, Apps, Automator, Scripts, Droplets, etc/Shell Scripts/audiocapture.sh: Permission denied

I get this error reading from the .sh file whether I add /opt/anaconda3/bin/ to the beginning of the script or not.

The error message suggests a separate issue – distinct from the earlier problem of finding the ffmpeg executable, which I think you have now resolved.

Something to do with:

etc/Shell Scripts/audiocapture.sh


  • The space between Shell and Scripts ?
  • Permissions settings audiocapture.sh ?
  • Permissions or path for access to /etc/ ?


As for the shell script issue with ffmpeg, this just came up in another thread, where it's really tricky to get the quotes correct when passing things in a var to ffmpeg due to embedded quotes. See @Nige_S' workaround in that thread:

(I posted a stupid silly solution which also works, which is to just type the command into Terminal via KM. Not the right way, but I was just trying to find any way to get it working :)).


Not really... the issue is that it seems that other people are able to use certain commands without having to add the path, whereas I can't. I wish I was able to just add the command without always adding that extra info. Now I have a saved action with that already in there, just in case, but it would be good to know what's causing that?
Initially it seemed that all I needed was that global variable (ENV_PATH), but it seems that it's not doing anything...

I was able to make the script and macro work and here's what I found (@griffman I will check your shared link as well):

We know that a path without quotes in Terminal, for example, needs to have the spaces escaped, right? So in my mind I thought "ok, so if I want to use the path in the Execute Shell action, the variable needs to have the escaped spaces", so that's what I did. But then when I want to include the variable in the Shell action, I have to use quotes like this "$KMVAR_Local__myVar", otherwise it won't read the variable, so it seems that this automatically makes the path work without the need to escape the spaces (similar to when we use a path with quotes in Terminal), so when it tries to read a path from a variable that has escaped spaces, it's using the \ as part of the path:
my/path/to\ a\ folder will be interpreted by the script as the real path, including the backslashs instead of"
my/path/to a folder

That seems to be the issue, as I was able to make the script and macro work after I understood this. I even took a note on my KM notes in case I forget about it.

So yeah, now I was able to make the macro work.
I still wish the issue with the ffmpeg path wasn't there though.

This may not be helped by using conda to install packages while most people use brew. While you should be able to make it work you may have limited your available Forum guinea pigs... Is there are reason you're using conda?

What error do you get if you don't run that? (I'm wondering if you might have a brew-installed version as well, and things are getting confused.) But you could try adding /opt/anaconda3: to the beginning of ENV_PATH so your conda installs are preferred over any others.

No, you don't have to use quotes. You wrap the variable in quotes so you don't have to escape the spaces in the variable, just like you wrap the path in quotes when you type it into Terminal. And since, as Mac users, we often use spaces in our file and folder names -- it's a good idea to always quote variables that contain paths.

Paths, shell variables, KM variables, and how they all work together is tricky. But keep the Wiki page to hand and you'll be OK.