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:
In the Finder, select the file I want to rename.
Press return/enter so that the file name is editable.
Type the string that activates my KM snippet, for example ;xyz
The KM snippet prompts for user input, I choose a value from a drop-down box, and click OK.
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:
Select file in Finder,
Press Enter to able to file name
Go to place in filename where I would wish to add date with the macro.
Type trigger XD1, adjust date, and press Enter
Date would be added.
Selected file would remain in editing mode
After installing Monterey and KM10.0
Select file in Finder,
Press Enter to able to file name
Go to place in filename where I would wish to add date with the macro.
Type trigger "xd1" But
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)
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
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.
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?
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:
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 "-?".