I have found this promissing macro by JMichaelTX (may he rest in peace) to rename PDF-files named 1.pdf, 2.pdf - 349.pdf (I don't know the exact number right now).
I have changed the columns in the Excel file, but I do not know how to change the regular expression to capture the filenames?
Hi Chris
I actually wanted to use the worksheet from Jim's Macro and only adjust the relevant lines there. the lines are:
1
2
3
4
(pdfs titles to be renamed)
and
Prename Name A_1
Prename Name A_2
Prename Name A_3
Prename Name A_4
(renamed pdf titles)
My first thought is that it's really a lot of trouble to fool around with Jim's very complicated macro without need – better to simplify if possible.
The task would be better done with a basic Excel worksheet or better yet with BBEdit and a more simple text table.
I recommend BBEdit because…
Although BBEdit is a commercial product, the trial version reverts to a
still very powerful and free (BBEdit-Lite) version after 30 days.
It is very Mac-like.
It has excellent support for RegEx.
It is very AppleScriptable.
It has a two versatile command line tools.
It has been in continuous development for over 25 years.
A text file is much easier to work with an manage than a spreadsheet, unless of course you're very familiar with the spreadsheet software.
By using BBEdit our data acquisition script becomes this simple:
# Acquire rename table.
tell application "BBEdit"
tell front text window
set renameTable to contents of lines whose contents is not ""
end tell
end tell
set renameTable to items 4 thru -1 of renameTable
Although using a simpler Excel workbook also gives us a much simpler data acquisition script:
# Acquire rename table.
tell application "Microsoft Excel"
tell active sheet of active workbook
set valuePairList to value of used range
end tell
end tell
if item 1 of valuePairList contains "Old File Name" then
set contents of (a reference to item 1 of valuePairList) to 0
end if
set valuePairList to lists of valuePairList
From either one of these places it becomes pretty straightforward to iterate through the old-name ⇢ new-name pairs and rename the files.
I can do either of these pretty easily.
The remaining question for you is where do you want the the target folder to be?
Do you want the front Finder window?
Do you want a specific folder path?
Do you want to pick the folder on the fly?
In general I think it's better to work with the file extension in the rename list, but that's not absolutely necessary.
Some people choose to hide file extensions in the Finder, and that can affect what you copy out of the Finder.
Hello Chris, I am a little ashamed that I caused such a fuss with this question. Thank you all the more for your solution. It's evening here with us right now. I'll get to work on it tomorrow morning and get back to you. Thank you very much in advance. Matze
Don't be – it's a perfectly reasonable question. It's just that Jim's solution here was designed around a specific user's request and is over complicated as a general solution.
I've been meaning to post a more general solution anyway.
I've provided a couple of building blocks but no solution as yet.
I've made two simple macros. One copies each name of the list of old names to "Copy 'Em". The other selects the old files in the Finder one by one and pastes the clipboards via Finder Rename.
The target window in the Finder must be open and frontmost.
What system are you running?
Try this on a dummy file or folder – run it from Apple's Script Editor.app:
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
set theItem to item 1 of finderSelectionList
set name of theItem to "NUTS!"
end tell
It should rename the selected item. Let me know what it does.
Running your Apple Script renames the selected file but only when a file is selected.
I have figured out why your first macro did not work. Excel Sheet was on an external monitor! If both Finder window and Excel Sheet are in the main monitor it works!
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
set theItem to item 1 of finderSelectionList
return (properties of theItem)
end tell