Folder Trigger to Process .mov Files Using HandBrake

So I am trying to create a folder action that converts any new file with extension .mov into an mp4 using Handbrake CLI.

So what I did is this:

Anything is added to folder “xxx” (ignoring partial or changing files)

## Will execute the following actions:

*For Each Item in the Collection Execute Actions
* The contents of folder “xxx” sorted alphabetically (reversed)

### Execute the Following Actions:

  * If All Conditions Met

    *The variable “VarName” contains “.mov”

### Execute the Following Actions:

    * Execute Shell Script

Get input from Variable “VarName”.

/Applications/HandBrakeCLI -v -i VarName -0 VarName.mp4

Stop macro and notify on failure.

but i can't get it to work - I am thinking that I am messing it up with the shell script... but I am not sure...

any help will be greatly appreciated!

Can you drag drop the macro itself into a post here ?

(Hard to spot things without seeing the detail and being able to test)

test converter.kmmacros (4.9 KB)

Can't speak for others, but just by looking at your Shell script, the reference to KM Variables is incorrect.

We need to use $KMVAR_VarName instead of VarName.

And, by using $KMVAR_VarName, you don't need the "With input from" part.

so i am trying a different approach -

but the $KMVAR is not printing the variable...

The action:Execute a Shell Script [Keyboard Maestro Wiki] says this:

Keyboard Maestro sets the environment variables for the script to include all your variables, using a prefix of KMVAR_ and your variable name with spaces changed in to underscores (_). For example, your Keyboard Maestro “File Name” variable will be available as the environment variable KMVAR_File_Name.

For a simple test, first just use a simple script such as echo $KMVAR_VarName to see if you are able to print the variable value.

Yeah - all I get is $KMVAR_File_Name - it is not displaying the value of the variable

Try putting $KMVAR_VarName in quotes if it is not surrounded by space.

It appears the original variable name can have underscores. See my test macro below:

#Test.kmmacros (2.8 KB)

🖼 Click to see screenshot

So I got it to work with terminal using the token -

but now the problem is that the HandbrakeCLI is not taking the file name because it is printed with spaces ...

but it needs to be printed like so:

/Users/ivg/IVG\ Dropbox/Ilya\ Gusinski/My\ Mac\ \(iMac.localdomain\)/Desktop/20-30\ IVG/20_IVG/20-03_Projects/23-03-P_Motion\ Graphics/00_PreRender\ to\ MP4/Play\ Start\ Armanda\ Bake\ adjust\ copy\

You can put the path in quotes. Then you do not need to escape space, etc.

do you mean this:

/Applications/HandBrakeCLI -v -i "%TriggerValue%" -o "%Variable%path%/test.mp4"?

because it didn't work... so I am guessing it's something else... could you please elaborate?

I meant

"/Users/ivg/IVG Dropbox/Ilya Gusinski/My Mac (iMac.localdomain)/Desktop/20-30 IVG/20_IVG/20-03_Projects/23-03-P_Motion Graphics/00_PreRender to MP4/Play Start Armanda Bake adjust copy"

instead of

/Users/ivg/IVG\ Dropbox/Ilya\ Gusinski/My\ Mac\ (iMac.localdomain)/Desktop/20-30\ IVG/20_IVG/20-03_Projects/23-03-P_Motion\ Graphics/00_PreRender\ to\ MP4/Play\ Start\ Armanda\ Bake\ adjust\ copy\

I don't know where you put it. What I suggested is for the Shell script.

but I need it to be printed out from a variable ... so how would that work?

I have no clue what you are doing. The path did not show up in your previous macro example.
Maybe you can post more information, including sample macros with screenshots. My knowledge is very limited. If I can't help, I'm sure someone else can help.

all I am trying to achieve is this: a folder action that works when a new .mov file is added to the folder it opens the terminal (so that I can see progress) and then encodes the file from MOV to MP4 using handbrakeCLI...

I see.

This should work. Have you tried it?

yep - tried it... if I put the variable in quotes it is ignored...

Sorry. I replied too soon.

It looks like the values are empty.

Something must have gone wrong.

I can't see your trigger.

In order for your macro to work, you have to use the "Folder" trigger and add a ".mov" file to the folder.

If you use use other triggers, it won't work.

i'll have to test some more and see if it'll work...