For Each Action Issue

If I don't use For Each action, everything works fine. ▼

Keyboard Maestro 8.2.4 “Clean Up Underscore” Macro

Clean Up Underscore.kmmacros (22 KB)

But if I add For Each Action around it, nothing will happen when there's only one side(starting or ending) has '_'. ▼

For Each.kmactions (4.3 KB)

Could anyone help to figure this out?

The problem is that you're not using the variable specified in the For Each action in your subsequent actions. I take it from the macro you've shown us that you're looking to erase underscores from the beginning and end of selected file names, so here's a macro that I believe should answer your question and hopefully solve your usecase in a simpler way than what you currently have:

Rename Files - Clean Up Underscore for Files.kmmacros (4.4 KB)

1 Like

@gglick Your regex is just simple and working. Thank you!

1 Like