Lowercase all files selected in Finder quickly

I can up with this but there is no lowercase option.

Try this:

  1. Change the For Each “Variable” to “FilePath”
  2. Split FilePath into ParentPath and FileName
  3. Use Variable Filter to make FileName lower case
  4. In the Move Block: %Variable%FilePath%
  5. In the to Block: "%Variable%ParentPath%/%Variable%FileName%

That may not be perfect, but should give you some ideas on how to build the macro.

1 Like

Hey Michael,

Thank you for your response.

Can you expand on pint 2, how do I split the file path variable?

Obviously you can't use the same variable for both.

No need to get the parent path because you can rename from a path to a file name if you don’t want to move the file.

So basically:

  • For Each FilePath in Finder Selection
    • Get File Attribute: File Name to variable FileName
    • Filter: Lower Case variable FileName
    • Rename %Variable%FilePath% to %Variable%FileName%

Unfortunately, while this looks like it should work, it actually will not because the file system is case insensitive and so a file with that name already exists (namely the file you are renaming to).

So you have to rename the file away, and then rename it back which does indeed require the parent path. Something like:

  • For Each FilePath in Finder Selection
    • Get File Attribute: File Name to variable FileName
    • Get File Attribute: Parent Path to variable ParentPath
    • Filter: Lower Case variable FileName
    • Rename %Variable%FilePath% to %Variable%ParentPath%/temp
    • Rename %Variable%ParentPath%/temp to %Variable%FileName%

I’m just curious, if you don’t mind. Why bother to make all files lowercase?

For me it is just a personal preference. It just looks better. :slight_smile:

1 Like

Maybe a simpler alternative in this case would be with an AppleScript:

use framework "Foundation"
tell application "Finder"
  set theSelection to the selection
  repeat with i in theSelection
    set name of i to lowercaseString() of (current application's NSString's stringWithString:(i's name)) as text
  end repeat
end tell

4 Likes

Oh wow, Tom, as I was struggling to implement Piter’s solution, here you give a one applescript solution that works perfectly.

Thanks for that. And for Piter’s and Michael’s help too.

The downside of the AppleScript solution is that it doesn’t help you learn how to use KM.

True, but the AppleScripted Finder solution is faster and easier unless the file-count is over about 500 or so.

A couple of edits:

use framework "Foundation"

tell application "Finder"
   set finderSelectionList to the selection as alias list -- most important change (faster than Finder references)
   repeat with theItem in finderSelectionList
      set name of theItem to (lowercaseString() of (current application's NSString's stringWithString:(theItem's name))) as text -- improve clarity of what is coerced to text
   end repeat
end tell

-Chris

2 Likes

Thanks for improving the script, Chris.

Hey Christopher,

Can you help me make sense of what I might have done wrong with this script? I want to move selected files to /Applications folder.

tell application "Finder"
	set finderSelectionList to the selection as alias list -- most important change (faster than Finder references)
	repeat with theItem in finderSelectionList
		move theItem to POSIX file "/Applications"
	end repeat
end tell

Not Christopher, but your script works fine for me.

However, you don’t need POSIX paths, and it can be written a bit simpler:

tell application "Finder"
  set finderSelectionList to the selection as alias list
  move finderSelectionList to (path to applications folder)
end tell
1 Like