Append a File Name


#1

I have a file converter app I use frequently that appends the file name with _converted at the end of the file name before the extension and I'd like to have a little script that will chop off the additional text. So Test_converted.mp4 would become Test.mp4 I don't need to move the file just need to rename. I've got one script that works fine when I just select a single file in Finder but doesn't work when I select more than one file so ideally I'd have one script that would work for one selected file or multiple selected files. Screenshot below where I've started trying to gleam from some other posts on here along similar lines but I've kept changing it with different bits and testing and at one point was closer than what is here but I'm trying! ha.


#2

Hey Clif,

You can't rename a file with Keyboard Maestro per se.

It works like the shell and to rename a file you “move” it to a new file with a new name.

This is one reason I prefer to use AppleScript for such things, because it actually renames the file in place.

I'm using the Keyboard Maestro Engine for regex support.

-Chris


Rename Selected Items in the Finder -- Remove String “_converted”.kmmacros (6.7 KB)


#3

THANKS! This worked absolutely perfectly and thanks for letting me know KM wouldn't do it exactly but working with AppleScripts in here or even directly with my StreamDeck work perfectly. Thanks for the help here and on the Safari bookmark one, that's two I owe you!


#4

Hey Chris,

How do you append text to the currently selected file name? I create an alias of files then add "Open Items" to the end of the file name so it is picked up by a Finder smart folder.


#5

Hey Bern,

You want the file or the alias to the file to carry the “Open Items” tag?

If the latter then this is probably the way to go:

----------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2019/02/19 04:35
# dMod: 2019/02/19 04:35 
# Appl: Finder
# Task: Create a New Alias and Alter Its Name.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Create, @New, @Alias, @Alter, @Name
----------------------------------------------------------------

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList ≠ 1 then error "Incorrect Number of Files Selected in the Finder!"
   
   set theItem to item 1 of finderSelectionList
   set itemName to name of theItem
   set newItemName to itemName & " – Open Items"
   
   make new alias file at (get insertion location) to theItem with properties {name:newItemName}
end tell

----------------------------------------------------------------

Any special reason you're using aliases instead of just tagging file itself with an actual system tag?

Keyboard Maestro can add, append, and remove tags.

Set File Attribute action

-Chris