I am really liking the “Quick Action” of Automator. So convenient and so efficient to use… I do have KM and Hazel, but I am hoping to channel all of my limited (Think Old) learning curve to one Program. For reasons beyond me, Automator makes me feel comfortable and willing to do the learning curve.
The files that I work with begin with the years such as "1932 - City.pdf"or “1892 - France.pdf”…etc…
I have used a program called “A Better Finder Rename 11” to rename “1932 - BetterLife” to “BetterLife - 1932” .
so if the year is different, I just adjust the year. Then select all the pdf’s with same year and run
I would like to create a Quick action with the same thought involved.
Can someone suggest a roadmap for me to use… what is difficult for me to understand, is how do I direct Automator to copy the first five characters , then delete the first five characters and then paste them at the end of the file
Shell scripting has been the de facto tool for file management since file systems were conceived. There’s almost always a way to do it from the command line as a result.
Based on that, my approach would be to use Automator to run a shell script against selected files to rename them.
Here’s how it looks.
Here’s the script.
for f in "$@"
do
new=$(echo $(basename "$f") | sed -E 's/^(.{5})(.*)\.(.*)/\2\1.\3/')
mv "$f" "$(dirname "$f")/$new"
done
Here’s a link to the Automator file; though obviously please do confirm the content before running it, and always have a good backup in place.
The script receives the selected file paths from Finder. It splits out the base name from the directory path and then used a regular expression as an instruction to sed (stream editor) to rearrange the components of the file name. With the new name, the directory path is prefixed to it, and mv (move command) is used to rename the file. This is repeated in the do loop for each of the files received.
Although this is above my skill set, I was successful installing…
Original 1880 - A Hot Wave (Sheet)
After - A Hot Wave (Sheet)1880
What do I have to do to make the outcome
Original 1880 - A Hot Wave (Sheet)
Would Like A Hot Wave (Sheet) - 1880
I really like the explanations given…It is very helpful to understand why and what it is doing… I changed {5} to {6} and this put in a space (I know what that does now)
What do I need to do to change to make “- A Hot Wave (Sheet)1880” to “A Hot Wave (Sheet) - 1880”
I think I understand the question, but the lack of formatting and break up of content does not help, so I could be wrong on what you are asking for.
I think you want to rename
1880 - A Hot Wave (Sheet)
With an unknown file extension to
A Hot Wave (Sheet) - 1880
To do that you need to modify the regular expression. There are a few ways to do this, but something like this for the match and replace should work I think (not at my Mac right now).
/^(.*) - (.*)\.(.*)/\2 - \1.\3/
This is based off splitting by “-” rather than character count, but from this example and the one above you should be able to see how to do it that way.
For this one, again a different regular expression, but I’m really just making wild guesses at this point of what your criteria are for splitting this up. It could be by particular characters such as spaces and closing parentheses. It could be by numbers of characters. It could be by matching numeric characters. It could be a combination of all of them. But for completeness, I think this would cause the change as written.
for f in "$@"
do
new=$(echo $(basename "$f") | sed -E 's/^(.*) - (.*)\.(.*)/\2 - \1.\3/
mv "$f" "$(dirname "$f")/$new"
done
but you should have
for f in "$@"
do
new=$(echo $(basename "$f") | sed -E 's/^(.*) - (.*)\.(.*)/\2 - \1.\3/')
mv "$f" "$(dirname "$f")/$new"
done
i.e. you have not closed the sed command’s substitution with the “'”, or the inline evaluation with the “)” - those two characters appear to be missing from the end of the line.
I’ve just logged on to my Mac and tried it and it seemed to give me what I think was the desired result based on your example PDF.