FFMPEG via Shell Script

Hi, Im trying to make an active folder that reacts when a video land in the folder and run a shell script doing a FFMPEG command which adds a 3D Lut to the footage. The shell script command works in terminal but when I try to modify it into KM it only shows a short notification macro cancelled and the ffmpeg credentials. How can I see the whole message not only what is compressed into the notification? And anyone seeing why the macro doesn't work?

Any help would be greatly appreciated :slight_smile:

Trond

34

In the Keyboard Maestro editor, select Help » Open Logs Folder which should open a folder such as ~/Library/Logs/Keyboard Maestro/. Then look in the Engine.log file.

Not immediately, but ffmpeg is not my forte.

Thanks for pointing me to the log Folder @tjluoma , that helped a lot! The error seemed to be connected to the -overwrite_original, I ended up bypassing this with saving the file into a subfolder and it works :slight_smile:

Trond

I got another problem with this macro when copying more than two files, since the macro runs when the first one is finished, it doesn't manage run it on all the files, is there any way of delaying the macro to start until the copying is finished?

I found an AppleScript solution here on the forum to wait until it was all copied.
05

But from there I have tried to put up a For Each Item in Collection to run through all the files in the folder and still it only manage to finish some of the files, not all, I think I have misunderstood the For Each functionality

12

The macro fires when the first file is being copied, and AppleScript waits for the copy operation to end, but maybe it starts the conversion after the first file is fully copied and not all of them. Since conversion is long enough to mask that fact you end up chasing the copy algorithm with the conversion algo. Maybe trigger the conversion on unplugging the external drive?

@NikolaKolodziejczyk I ended up triggering it with a keyboard shortcut and that works really good! However I also saw somewhere the possibility of using automator to make a file service from finder. And triggering KM from there. Here is what I got so far:

Unfortunately it fails saying 64:65: syntax error: Expected «"», but found Ukjent token. (-2741)»
Anyone know how to fix this?

Thanks
Trond

You don't need to use two lines for this, you can just do it all on one line, like so:

osascript -e 'tell application "Keyboard Maestro Engine" to do script "FFMPEG Square"'

and that should work. You also should not need to escape \ the space in FFMPEG Square if you do it that way.

However, my guess is that this still might not work because FFMPEG Square may not be found in your default $PATH so I would recommend using the full path, like so:

osascript -e 'tell application "Keyboard Maestro Engine" to do script "/path/to/the/file/FFMPEG Square"'

Again, that should all be one long line.

Thank you :slight_smile: The first line worked perfectly! That probably means I had declared the $PATH correctly. But just to clearify the second option, FFMPEG Square in this case is a Keyboard Maestro macro, which file would this then point to? Is there a folder where the KM macros are stored?

Thanks again for your help :slight_smile:
Trond

Ah, a Keyboard Maestro macro is not a script.

Open Keyboard Maestro, select your macro, and near the top (under the Triggers) there will be a small line that says "Or by script" which you can select.

Select it and choose "AppleScript" and it will show you the proper syntax for executing that particular macro.

I have set up something similar to this. When I drag a file into the trigger folder, the process begins but what I have NO idea about is how far through the process it is. Is there a way to monitor an encode process like this?

I think not – not when running from Keyboard Maestro's Execute a Shell Script action.

You could have the process run in the Terminal.app instead, and since the Terminal is an interactive environment it should be able to show progress.

-Chris

Ah, I think I shall take a different tactic then: start processes before I head to sleep. A watched kettle never boils, and all that. :slight_smile: