Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tommaloney

macrumors newbie
Original poster
Jan 7, 2022
6
0
Hello everyone,

I need help with OS X Automator. I am looking to make my life a bit easier with the small project I am working on. Just say these are the type of files I have ABC.123 (the extension .123 always changing). What I would like to have is an automator set up so that it would ask me to select a folder. Then it would rename the files inside that folder sequently with the extension of .pdf and the parent folder name.

So Test would be the folder I selected.
(Example Test/ABC.123 -> Tests-1.PDF , ABC.345 -> Test-2.PDF ...)

I hope I am being clear enough with my idea.

Right now, I have automator letting me select my files (not folder), I am finding ABC. and replacing it with a blank space. then renaming the files sequently. then adding the extension as .pdf. then I have to manually copy and paste the folders name to each file. its time consuming. when there are litterly thousands of files.

Any help would be greatly appreciated.

Thank you
 
If these are all PDF files that have the same name, just different extensions (for page numbers or whatever), can you just tack on a .pdf extension, or are some of the extensions the same?
 
Shell script to do it is pretty simple.

Code:
#!/bin/zsh

#
# script takes as input pathname to a folder and then renames all the files in the folder
#

cwd=`pwd`

cd "$1"

x=1

find . -type f -maxdepth 1 -name '*.[0-9]*' | sed "s/\.\///" | while read -r File; do
   froot=`echo "$File" | sed "s/\.[^.]*$//"`
   idx=`printf '%02d' "$x"`
   ((x++))
   mv "$File" "$froot""$idx"".pdf"
done

cd "$cwd"

exit 0
 
  • Like
Reactions: jdb8167
Or can replace

Code:
find . -type f -maxdepth 1 -name '*.[0-9]*' | sed "s/\.\///"

with

Code:
 ls -1 *.[0-9]*

Should do same without the extra baggage.
 
Thank you for this, but sadly I cannot get it to work. I have added this to automator under variables/utilities/shell scripts. Is it possible to make a automator app or workflow and attach it here? I know I am asking a lot.
 
Guys I really need help with this,

Is there anyone out there that can make me an automator workflow that renames files sequently and changes the extension. while adding the parent folder to the name. Regardless of the file name or extension.

I have this

Parent Folder/ABC.123
Parent Folder/ABC.XYZ
Parent Folder/ABC.789

I need this
Parent Folder/Parent Folder - 01.pdf
Parent Folder/Parent Folder - 02.pdf
Parent Folder/Parent Folder - 03.pdf

Please help

Thank you
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.