Newbie Question - Passing a Variable to the Script Does Not Work

Hi, I would like to use a script to tag my image files selected in the Finder.

Unfortunately, I get an error in Terminal:

Last login: Sun Oct  9 17:53:49 on ttys000
You have mail.

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
MBP-2021:~ micha$ km1='/Users/michaelschwaiger/Downloads/File1.jpg'; /usr/local/bin/exiftool "-keywords=TESTKEYB" "$km1"
Error: File not found - /Users/micha/Downloads/File1.jpg
    0 image files updated
    1 files weren't updated due to errors
MBP-2021:~ micha$

I'm a complete beginner unfortunately, what am I doing wrong with the passing?

Thank you very much for your support.

Thank you. I definitely need to check this.

Thank you for your support. I tried your Macro, but I can't see the keyword when I check the file.

@noisneil’s macro is setting a Finder Tag whereas you’re trying to write an EXIF tag to the file which as you know are two completely different things.

1 Like

Oops. :man_facepalming:t2:

I’m not sure why you’re using the 3rd party plug in to run your shell script in terminal. You do know that KM has a built-in action to execute shell scripts? It’s documented in the KM wiki here: action:Execute a Shell Script [Keyboard Maestro Wiki]

In addition, there is a huge amount of discussion in this forum regarding running shell scripts so be sure to check that out too. In particular - search this forum for “EXIF” and you’ll get lots of hits.

2 Likes

Thank you very much! In fact, I had checked the forum here once for the task I want to solve (tagging image files with keywords). That's where I got the example from, but couldn't successfully implement it.

I'll have a look at your link and look for more examples.

Thanks again

Let us know how you get on!

Sorry for the late reply, but I was on vacation the last few days.

Thanks for your hints, unfortunately I didn't manage to find the right hints for me in the forum, or with the help of the built-in action to execute shell scripts to solve my problem.

I have now copied the files I want to save with the keywords to a temporary directory. If I now run my original script, and use the folder name instead of the file name in each case, it works. Even though this is a roundabout way, this solves my problem. Thank you very much for the time you have taken. Unfortunately I am not a (good) programmer and could not implement your hints.

I hope you had a nice break!

Well it’s good that you’ve found a solution even though it’s a bit of a workaround.

Whatever our level of expertise we all need help now and then, so do feel free to ask other/further questions.

The bit that worries me from your OP is

MBP-2021:~ micha$ km1='/Users/michaelschwaiger/Downloads/File1.jpg'; /usr/local/bin/exiftool "-keywords=TESTKEYB" "$km1"
Error: File not found - /Users/micha/Downloads/File1.jpg

Why is the error reporting a different path to the one you've given it? Why does the prompt show micha in the bit that usually shows the short username while the user home directory (which usually matches the short username) is michaelschwaiger? But for all I know that might be down to the plugin you are using.

Also, the quotes look a bit wrong -- I'd expect the first argument to be -keywords="TESTKEYB".

This would probably be easier to troubleshoot if you uploaded the macro, rather than an image of just a part of it -- and, ideally, one that used the native KM action rather than a plugin. So try posting that if you'd like to avoid the "duplicate then tag" workflow.

Correct, this is an inconsistency as to the username as to the prompt and download directory. I had tried to avoid giving the full name here, hence no screenshot, but I forgot to change the name inside the download path as well. So the return of the script is identical to the original username.

Thanks again for helping me troubleshoot, but I'm happy with my workaround for now. I would like to dig deeper into this though, I still have too many gaps here and would like to work it out.