Execute Shell Script – Using Sox with KM

Hi,

I'd like to get launch a terminal command to work with files in a specific folder.

My command is very simple:

sox -m PATH_OF_FILE_A PATH_OF_FILE_B (PATH_OFRESULT.FILE

I will always put the files to mix (with sox) in the same folder and I always want the result to be in the same folder.

But I'm stuck with copying the name of 2 different files and pasting them in the terminal command...

For example, my folder is:

/Users/flag/Desktop/mix

My files are: 1.mp3 and 2.mp3

The command is:

sox -m /Users/flag/Desktop/mix/1.mp3 /Users/flag/Desktop/mix/2.mp3 /Users/flag/Desktop/mix/result.mp3

Can you help me please?

Thanks!

Is the plan to select the 2 files to process in the Finder.
Or are the always placed in the folder mix on the Desktop and named 1.mp3 and 2.mp3?

Thanks Jimmy!

We can envisage both options.
If we place them in the folder mix, maybe we can add a "copy and move" action (from the original location to the mix folder) before processing the files...

Here is a macro which takes the 2 selected files and runs the sox command.
It checks for 2 files and places the output in the first files location.

What does the sox command do?

SOX Macro (v10.2)

SOX.kmmacros (7.3 KB)

Thanks Jimmy, looks great, but I cannot launch it...
Without selecting 2 files, I can hear the beep.
With 2 files selected, nothing happens.
Any help?

I'm using the sox command to mix two audio files together. It's useful when you recorded with separate tracks and when you can to mix them into only one file...
https://sox.sourceforge.net/sox.html

Thanks again

Did you see a pop up where you were asked to allow Keyboard Maestro Engine to control Finder?

No...But I granted access earlier.

Can you try to add
export PATH=/usr/local/bin:$PATH;
before sox in the shell script action, so it looks like this:

Thanks, but it does not work.
I think the macro is launched because the data here are updated with my own computer...

I realized you wrote the macro with *.mp3 files and I tried to make it work with *.WAV files. I converted the WAV into MP3, but it does not work either...

Thanks again.

The location of the files is not hardcoded into the macro.
The screen shot just shows some temporary information from when I ran the macro.
I am a bit of a loss about what happens. It worked here on my computer.
Can you try to add a Display Text in Window action with the variables and then post the result?
Like this:

Thanks Jimmy,

  • I tried to add the "display text" action at the end of the macro and nothing happened.
  • I moved it up one level in each test until it works.
  • It works just before the shell script, but the window is empty.

You forgot to write the names of the variable correctly:

%Local__mp3A%

%Local__mp3B%

%Local__OutputMP3%

Oops!

Thanks.

Here is the screenshot, working only before the shell action

Can you open the Terminal app and run the command:
which sox
and share the output.

Maybe the shell script can not find the binary without the full path to the binary.

Thanks,

Here is the result:
/opt/homebrew/bin/sox

Then change the Execute shell action to:

export PATH=/opt/homebrew/bin:$PATH;
sox -m "$KMVAR_Local__mp3A" "$KMVAR_Local__mp3B" "$KMVAR_Local__OutputMP3"

EDITED to reflect @Nige_S’s comment

And if you want to change the output to WAV, change the extension here:

Or the macro could ask for Output format when it is run.

...or don't bother setting $PATH at all, and use the full path to the utility:

/opt/homebrew/bin/sox -m "$KMVAR_Local__mp3A" "$KMVAR_Local__mp3B" "$KMVAR_Local__OutputMP3"
1 Like

Thanks again, but it does not work...

When asking for the dialog window before the shell script, I can see the right paths.
It seems the issue comes from the shell action

Thanks!

THANKS!

This solution is working!