KM, Folder Trigger & Shell Scripts

I'm new to KM so please forgive me.

I have set a trigger to activate when files are added to a folder. It runs an 'Execute Shell Script' action. What I want to do is set some tags on the file using the MediaInfo app so that when I then add the files into iTunes it will automatically get the artist, genre etc.

In the KM macro I started by creating a noddy example just to show me the filename but it won't work. I think it should be using %TriggerValue%. I tried:

echo "1 $KMVAR_%TriggerValue%"
echo "2 $KMVAR%TriggerValue%"
echo "3 $KMVAR_TriggerValue"
echo "4 $KMVAR%TriggerValue%"
echo "5 $KMVARTriggerValue"
echo "6 %TriggerValue%"
echo "7 %Variable%TriggerValue%"

but the result (and for some reason I get two result windows popping up) is:
1 %TriggerValue%
2 %TriggerValue%
4 %TriggerValue%
6 %TriggerValue%
7 %Variable%TriggerValue%

As a test I put a 'Display Text' action after this in the macro to display %TriggerValue% and that works fine.

Can anyone point me in the right direction?

1 Like

Oh, and I also added:

None of those had the filename either.

Hey Mark,

%TriggerValue% is a text-token not a variable.

To use it in this fashion you'll have to put it into a variable first.


1 Like

When you run a script via Execute Script, all your Keyboard Maestro variables are available via the KMVAR_ variables.

%TriggerValue% is a text token. You cannot access text tokens from a shell script except by running this AppleScript (although I suspect you wont actually be able to get that value since you’re not within the macro at that point) :

tell app "Keyboard Maestro Engine" to process tokens "%TriggerValue%"

What you need to do is store the %TriggerValue% text token value in a variable first. So basically:

  • Set variable “Added File” to text “%TriggerValue%”
  • Execute Shell Script: echo “$KMVAR_Added_File”
1 Like

Ah, thank you so much, this now works.

One step forward :wink:

1 Like