2
votes

I often have to rename lots of files - e.g. append stuff to the file name (before the file-ending). E.g. mywords.txt -> mywords_addedtext.txt

So I'm trying to make an OSX-service, that enables the following work-flow:

1) I select a bunch of files in Finder:

mywordsA.txt
mywordsB.txt
mywordsC.txt

2) I start my service "MyFilenameAppender"

3) An input-box appears: What do you what to append?

4) I type in something, e.g. _addedtest

5) The files are renamed:

mywordsA_addedtest.txt
mywordsB_addedtest.txt
mywordsC_addedtest.txt

(the files aren't moved or copied)

I've tried the following steps in Automator:

a) "Choose a type for your document." -> Service

b) Service receives selected: "files or folders" in "Finder"

c) "Ask for Text" action

d) "Set Value of Variable" -> the text from c) set to a "textToBeAdded"-var

e) "Rename Finder Items" -> "Add Text" -> append the "textToBeAdded"-var

But the "Rename Finder Items" doesn't seem to get the text.

Can anyone please help me? This would be very useful to me! :-)

3

3 Answers

3
votes

It looks like you have everything you need, except the order is incorrect. Ask for Finder Items should come after setting the variable, otherwise Automator loses the information:

Automator Rename Items

1
votes

Thanks a lot for the input, l'L'l! Your answer is beautiful, and got me on the right direction!

However, I like to select the files in finder first and the rename - your solution was the other way around. Just my preference!

So on top of your solution I made this:

a) "Choose a type for your document." -> Service

b) Service receives selected: "files or folders" in "Finder"

c) "Set Value of Variable" -> "filesToBeRenamed"-var (stores the files, I want to rename)

d) "Start Applescript" -> "activate" (to switch focus to the upcoming textbox)

e) "Ask for Text" action

f) "Set Value of Variable" -> "textToBeAdded"-var

g) "Get Value of Variable" -> "filesToBeRenamed"-var

h) "Rename Finder Items" -> "Add Text" -> Add: "textToBeAdded"-var (after file name)

This seems to work - any suggestions on improving it, are of course very welcome! :-)

0
votes

The answer from user765151 above worked great for me, so I thought I'd include a screenshot of that so people can see how that looks, at least on OSX 10.13. Automator script window