KM10 - Error When Using Snippets to Rename Files in the Finder

I recently upgraded to Keyboard Maestro 10 and am now having a problem with snippets, specifically when renaming files.

Following are the steps that I take to rename files with KM10, which worked without issue in KM9:

  1. In the Finder, select the file I want to rename.
  2. Press return/enter so that the file name is editable.
  3. Type the string that activates my KM snippet, for example ;xyz
  4. The KM snippet prompts for user input, I choose a value from a drop-down box, and click OK.
  5. The file is renamed and I press return/enter to complete the file renaming process.

In KM10, when I do step 3, the file to rename loses focus (I never paid attention to what happened here in KM9 because it worked without any errors), the file is renamed to ".txt" (or .pdf, etc.) and I get the following message:

"You can't use a name that begins with a dot ".", because these names are reserved for the system. Please choose another name."

Has anyone else encountered this issue with KM10? If so, is this a bug or am I doing something wrong/need to update my workflow for KM10?

In case it matters, I'm running KM10 on macOS Catalina 10.15.7.

I have been using the following macro (which another user of KM posted) for years - but now is causing an issue when used in Finder in the following way. I do not know whether the problem is with a change made by Monterey or KM 10.0.

Prior to installing Monterey or KM 10.0 I would do as follows:

  1. Select file in Finder,
  2. Press Enter to able to file name
  3. Go to place in filename where I would wish to add date with the macro.
  4. Type trigger XD1, adjust date, and press Enter
  5. Date would be added.
  6. Selected file would remain in editing mode

After installing Monterey and KM10.0

  1. Select file in Finder,
  2. Press Enter to able to file name
  3. Go to place in filename where I would wish to add date with the macro.
  4. Type trigger "xd1"
    But
  5. after typing the trigger "xd1" (and nothing more) Finder exits the editing mode of the selected file.

I would be grateful to know where the problem lies.

Insert Date offset by number of days supplied by user Macro (v10.0)

Insert Date offset by number of days supplied by user.kmmacros (3.5 KB)

1 Like

Hey @peternlewis,

I consolidated these two threads into one, because they look to be the same issue.

-Chris

My apologies for failing to include a sample macro for this issue. Here's a copy of the macro I'm using, tweaked a bit to have different values in the prompt, but it still causes the same problem I reported.

KM10 - Error When Using Snippets to Rename Files in the Finder

Bug.kmmacros (2.3 KB)

1 Like

Hey Guys,

Okay, thanks to both of you for providing test-case macros.

This problem happens to me on Mojave, so it seems the culprit is Keyboard Maestro 10.

When the User-Prompt window pops up context is shifted away from the Finder, and the rename session is cancelled.

This kind of issue has been seen with many utilities over the years, and I have no idea if Peter can fix it in view of changes made in KM10. We'll have to wait for him to weigh in.

While I use text-substitution all the time to rename items in the Finder, I don't ever use a combination of text-sub + Prompts.

When I want to do that I operate directly on the selected item and bypass the Finder's rename mechanism.

set kmInstance to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
   set newItemName to getvariable "local_NewItemName" instance kmInstance
   
   # Example of how to set a Keyboard Maestro variable.
   # setvariable "local_KM_VarName" instance kmInstance to dataStr
end tell

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
   set theItem to item 1 of finderSelectionList
   
   set name of theItem to newItemName
   
end tell

Of course you can also use Keyboard Maestro's Move or Rename a File action, but I prefer AppleScript.

-Chris

While we wait to hear from Peter, is it possible to downgrade from 10 to 9? The wiki covers downgrades up to version 9, but not version 10. Do we know if the 10 to 9 steps are the same as the 9 to 8 steps?

It should be pretty much the same.

Make a full backup of this folder first:

~/Library/Application Support/Keyboard Maestro/

And you should be safe no matter what.

-Chris

I have looked in to this already.

The Finder rename stops immediately the Finder loses focus.

Previously, the Prompt For User Input only partially switched to the Keyboard Maestro Engine, so it managed to allow the Finder rename to continue, but realistically that caused other problems (probably some of the lost key strokes in the popup menus are related to that for example).

So I'm afraid the “feature” of only partially losing focus in the Finder is not coming back.

However, generally there are other ways you can do this that will work around the problem, often in elegant ways.

For example, with @VWKM’s macro, you can use a regex Typed String trigger of:

xd1;(-?\d+);

(just an example, adjust as desired).

Then get the number out of the TriggerValue token

image

So now you press return to edit in the Finder, and type “xd1;-5;” and that is replaced by the date five days ago.

You can also use the %|% token to specify where you want the text cursor to end up if you want to be able edit the date further.

1 Like

Peter,

Thank you for the explanation and the replacement way of getting the macro to work.

One question, not being very knowledge about regular expressions:

I understand what "\d", "+" "( )" and "?" all do in regular expressions, but what does the "-" do. I can see from Regular Expressions - ICU Documentation that "+?" represents: "Match 1 or more times. Match as few times as possible.", but there does not appear to be anything for "-?".

Thank you for the reply @peternlewis. I think for now I’ll downgrade to KM 9 where my macros are working without issue.