Get typed string to variable

Firstly I 'm trying to figure this whole process out. To hopefully understand it.

What I am trying to do is use a scanner to rename files.
So when I scan it I need the EAN to rename the selected file but if I have scanned it before I need it to add _2 and somehow if 5xxxxxxxxxxxx_2 exists then make it _3.

What i was first trying to do is add the scanned string to the variable so it can compare the previous scanned item.

This is the reg expressions that I am using

Hope that makes sense

Sorry, but I don't understand.

Please provide a real-world example of:

  1. File name that you want to rename
  2. File name AFTER the rename
  3. Detailed rules for renaming

And, how are you selecting the file(s) to rename?

It would be best to upload your macro so we can see exactly what you are trying to do.

Please read:
Tip: How Do I Get The Best Answer in the Shortest Time?

You can rename with an index something like this:

Rename with Index Macro (v9.0.6d2)

Rename with Index.kmmacros (5.1 KB)

Basically, you have to first test whether the target file exists, and then if it does, you need to keep incrementing an index until you find one that doesn't exist and use that.

It's non trivial to get it correct, so use some caution.

1 Like

Barcode Scanner Trigger.kmmacros (25.3 KB)

I've almost got it working as I would like.
The only issue I have is that where I manually select the file (highlight) this may then not be the file that gets renamed.

For example if you have the files

If I select 3.jpg then scan, the first interaction from the scanner begins with the number 5 and therefore will jump to file 5.jpg, and then this one gets renamed.
I would need it to remember the trigger value but not let it input to the finder?
so that the originally selected file remains selected