Keyboard Maestro Error on accented characters

I'd like help with moving files with accented characters.

I've created a macro that copies a file to a special directory and then formats the file name (without the path) into a format specifically needed by a program I'm using. It works great usually. Only I've found what appears to me to be that some characters that are legal for file names in MacOS are not handled correctly (fatal error) by KM.

Below is one particular error caused by the "ü" which KM converts to "Ãà". Maybe (most likely) I don't understand what is going on here and how to fix this. It is unusual for me to have filenames with these accented characters so I was just lucky to pick this one for testing. It is the move command in my KM macro that is failing.

Filename in Finder
⁨Music⁩/⁨doubleTwist/Ton Rückert/Wakka Chikka Wakka Chikka - Porn Music For The Masses Volume 1⁩/05 It Was A Dream.mp3

From engine.log
The filename in Keyboard Maestro during Move
] Move
), NSDestinationFilePath=/Users/will/Dropbox/zettelkasten/media/05_It_Was_A_Dream.mp3, NSFilePath=/Users/will/Music/doubleTwist/Ton RuÃàckert/Wakka Chikka Wakka Chikka - Porn Music For The Masses Volume 1/05 It Was A Dream.mp3, NSUnderlyingError=0x600002de5680 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} In macro “Copy Photo to Media Archive” (while executing Move or Rename File “%Variable%oldFilename%”).

Where do the names come from?

Create a complete macro that fails in order to figure out where things go wrong.

For example, try just the action:

Move file from “/Users/will/Dropbox/zettelkasten/media/05_It_Was_A_Dream.mp3” to “ /Users/will/Music/doubleTwist/Ton Rückert/Wakka Chikka Wakka Chikka - Porn Music For The Masses Volume 1/05 It Was A Dream.mp3”

Does that work?

As well as normal encoding issues (which is what this looks like), the file system has the added issue of dealing with decomposed characters. This looks like a just an encoding issue though.

Yes, it seems an encoding issue. But where and how to fix so macro doesn't fail? That is the question.

The names come from a filename that is highlighted in macOS Finder Window. In this case an mp3 file.

Screenshot and macro below.

This works and keeps the "ü" accurately.

More testing has lead me to the notion that I'm approaching this macro wrong. It fails not when I specify the files but only when I use a variable and no just any vairiable, the variable %TriggerClipboard%. I don't remember where I saw this but %SystemClipboard% wouldn't work in this application.

Some how I want to highlight a file in Finder and copy it to /Users/will/Dropbox/zettelkasten/media/ changing 'spaces' to '_' then create a text string '' to be pasted into second app.

I'm going to look at 'For each path in Finder selection'

Copy to Media Archive.kmmacros (3.6 KB)

Using Copy to get the path to a file in the Finder is not a good idea. It does not behave very well.

Use the For Each action with the Finders Selection collection to process selected files in the Finder.

Like this:

For Each.kmactions (1.7 KB)

Thank you so much. Yes, it turns out the "Copy" method was the problem. Switching to "for Each Item in collection" set it Finders Selection works great.

Now a new question arises. 'For Each' implies multiple files can be selected. Indeed when selecting two files both get copied to the new directory but only one is available in the System clipboard (the last step). Is there a way to iterate the pasting so each file (each item) gets appended such that the system clipboard looks like this when three files are selected in Finder? Or is there a way to prevent more than one file being selected?

Sure. The best way would probably be to accumulate it in a variable, something like this:

  • Set variable Output to ""
  • For Each
    • Set Variable Output to "%Variable%Output%newstuff%Return%"
  • Set Clipboard to Text "%Variable%Output%"

You could just add a Break From Loop action to the end fo the loop to just process a single file.

But since you are selecting multiple files and running the action, that would seem counterproductive.

Thanks yet again. You have been so helpful. I'm learning a lot about macro building. I idea of accumulating text to a variable is easy for me to grasp. What is a bit of a challenge is the actual implementation? Where in the loop it should occur? And what are some of the KM tricks that can be used? You mentioned a null "Output" variable and a variable called "Return". Both new to me.

I see how this should and could work. I want to cogitate with this a little.

I read ComplexPoint's article and I'm not sure it helps or confuses me.

Suggested option for the excellent For Each action – Map


Specifically JMichaelTX’s post shows how to append to a variable. Here is an example:

Thanks again. You are going the extra mile, helping me like this. I got the variable iteration working so I can select and work with multiple files. This works better than I hoped and had to add a "Display Text" message when it is done otherwise without an error, I get no feedback.

One unrelated question, how do people take the long screenshots of the macro build for posting on this forum? Searching the web I only find 'SnagIt' an expensive app that claims it can capture "Scrolling Screen Capture"/ Is this what you use?

It is best to post unrelated questions to a new topic so people can find them and the answers.

You can share a macro image directly to the forum from the Keyboard Maestro share menu. See: How to Post/Upload Your Macro to the Forum.