Resizing an image file macro

Resizing a file

Hi,

I'm having trouble with this macro. I had a version working on a folder trigger, but it proved messy as I moved files around. Now that I've turned it into a status menu trigger, it's not working at all. I largely copied this macro from the forums, I don't fully understand if the 'file' variable specifically refers to files or if I could have used any variable name there, I presume the former. I have tried various things, I'm obviously missing something basic!

I have appended 600x400 and 743x200 to the filenames respectively that can't be seen on the images, so they don't overwrite. I would like to get rid of the pathnames there and write the file in the same directory that the file is in as well.

Could someone help?
Thanks.

oldImage

It's hard to tell from your screenshot alone, but you're not using the same variable name in the "Write System Clipboard to File" action that you are in the "For Each File" field. I'm guessing you haven't upgraded to KM 8 (yet)? One of its many useful additions is that it warns you about just this kind of error. At any rate, this worked for me, so it should work for you too, and will hopefully be a more clear example of how this kind of macro works:

Copy and resize finder images.kmmacros (4.6 KB)
image

I originally just used the new KM 8 action "Split Path" to acquire the currently selected files' parent path and name, as I find it a much simpler, compact, and easier to understand action than the multiple "Get File Attribute" actions KM 7 and earlier used, but after figuring that you're probably still on 7, I opted to use the latter to show how to accomplish this goal with either version.

1 Like

Thanks, yes I was using %Variable%File% in the "For Each File" and %Variable%Filename%
in the "Write System Clipboard to File". Once I replaced 'Filename' for 'File' it didn't need a path as such, as it was built into the file (I don't know the terminology but hopefully you know what I mean), which actually worked.

I actually am using KM 8.2 so I don't know why I didn't get the error msg that you say I should have.

You're macro does make some things clear. Firstly, any variable name can be used - you used %LocalFile%, I see it is the action that designates it as a file variable. I know that has another name too, I need to go read the variable wiki again, but real life examples always help me. That's exciting, it means I could use reg ex to go back one level in the folders, create a new folder with a variable name and save the files there (for example).

I'll start trying to implement your macro - it has great flexibility, but mine's also working now, so thanks!

Below is the macro I should have attached at the beginning, but with the changes made so it works now.

Resize Image.kmactions (489 B)

1 Like

It only warns if the variable of a For Each action is never used. Its not smart enough to know if it is not used enough.

1 Like

Hey Damian,

This is a very common issue for people who are just starting to use Keyboard Maestro's collections.

“File” in this case is indeed a variable name.

Personally I nearly always use the variable name pathVar (for any collection that uses file-paths) so that anyone looking at the macro can tell at a glance it's a variable that refers to a path.

-Chris

1 Like