Shell scripting is very foreign to me, but I got this from a forum where I can normalize WAV files to -1dB, if I select the files in Finder and run it as a QuickAction.
#!/bin/bash
normalizationValue="-1"
for f in "$@"
do
normalizedFolder="$(dirname "$f")/Normalized ${normalizationValue}"
fileName=$(basename "$f")
if [ ! -d "${normalizedFolder}" ]; then
mkdir "${normalizedFolder}"
fi
/Applications/sox/sox --norm=${normalizationValue} "$f" "${normalizedFolder}/${fileName}"
done
I don't recognized the application that you are showing in the screenshot. What's a "QuickAction"? Is that something in macOS Automator?
You can't use KM variables in other apps that start shell scripts, you can only use KM variables when using KM actions like Execute Shell Script. If your plan is to copy the script from your app to the KM Execute Shell Script action, it may work.
A QuickAction is something you add to the Services folder and then you can access that when you right click an item. For example:
The other image is Automator, yes. Then I exported it as a QuickAction.
Yes, that's what I want. So now I have that script that's being used via the QuickAction. These are applied to the selected items. Similar to KM's "Finder Selection".
So now if I want to use that script with KM, since I'm using the FOR EACH and a variable is assigned to each item, I will probably have to add that variable to the script (inside the Shell action).
If you want to use the KM Execute Shell Script action, then you aren't using Automator anymore. As far as I know, you have to choose between these two apps for running your script. If you use KM, I don't believe you can make an Automator service, but if you want an Automator script, then you can't use KM's features because Automator is running your script. I'm under the impression that you still want to use both.
"$@" in the original script is pulling in standard input (stdin), which we're side-stepping by calling a $KMVAR_ directly.
I don't have the required audio program, so I changed /Applications/sox/sox to a simple cp
Thoughts on future development:
This could be reworked to remove the for loop in the Shell script, because currently we're only sending it a single file each time from the Keyboard Maestro For Each loop.
Alternatively, this could be reworked to send the Shell script the list of files from the folder, in which case the Shell script would only have to be executed a single time.
I don't think you need to bother reworking it unless you want the practice. Unless you're operating on thousands of files, I think the performance differences will be negligible.
Hey, no worries! I could also be wrong; we're all just doing what we can to understand the issues, have fun working the problem, and help out whenever possible.
Yes, @avtraino you are right. I don't want to use both, just KM (no Automator).
I was mentioned Automator, because that's something I've been using and it works, but I wanted to use the same script from Automator, in KM and since the Quick Actions act on selected items, I was guessing that KM would need something similar to target each item in the FOR EACH action.
This could be reworked to remove the for loop in the Shell script, because currently we're only sending it a single file each time from the Keyboard Maestro For Each loop.
[/quote]
I guess that was included in the original script because the Quick Action targets all selected files in Finder. That's my guess.
So I guess I can make that change again to the original script to use SOX, right?
I will try it tomorrow and let you know how it goes.
As @avtraino mentioned, I am trying to replace the Automator version with the KM only. I just mentioned the Automator and Quick Action, because that's where that script comes from. Sorry for the confusion.
Here's the script you can slot in if you don't want to fiddle with it
#!/bin/bash
normalizationValue="-1"
for f in "$KMVAR_local_TestFile"
do
normalizedFolder="$(dirname "$f")/Normalized ${normalizationValue}"
fileName=$(basename "$f")
if [ ! -d "${normalizedFolder}" ]; then
mkdir "${normalizedFolder}"
fi
/Applications/sox/sox --norm=${normalizationValue} "$f" "${normalizedFolder}/${fileName}"
done