1
votes

I have tried all day now to do the following: I have a folder with 99 subfolders. each subfolder has a pdf file inside and they all have to be renamed to carry the same name. now they are named with continuous numbers. I have been doing all my stuff with the automator as I am a novice to scripting. but i kinda don't like giving up on a problem. googling did not bring any good solutions. i have tried to make sense of example scripts and amend them, but had no success. a short try was:

tell application "Finder"
    set selected to selection
    open selected
    get files of folders of selected
    set name of files of folders to "anschreiben"
end tell

I have also tried:

tell application "Finder"
    set selected to selection
    open selected
    set mlist to every folder of selected
    set current_folder to first item of selected
    set xxx to first item of current_folder
    set name of xxx to "yyy"
    repeat with this_folder in mlist
        open current_folder
        set item 1 to item of current_folder
    end repeat
end tell

, but this renamed the first folder to yyy and produced and error that the file name is already given (because it renames the subfolders, not the files inside)

SO...how do I get on level deeper and rename all the files in the subfolders??

Thanks guys, I know it's probably easy for you.

2

2 Answers

0
votes

Look for "entire contents"

set newName to "New.pdf"

tell application "Finder"
    set myFiles to every file of (entire contents of (first item of (selection as alias list)))
    repeat with aFile in myFiles
        set aFile's name to newName
    end repeat
end tell
0
votes

it is done! Thanks to you and one or two other pros I now have a beautiful bulk mailing script routine using automator, a bash line and (mainly) applescript. I use it for job applications but you can use it for any case where you want individualised bulk emailing with Mail, MS Word and any given list of contacts in Excel (or Address Book for that matter). For the sake of being complete I will add all necessary steps. with any given list of x names, email addresses, personal addresses you can generate x subfolders, containing x personalized letters and not-personalized documents. once you start the last script and select the folder you can watch mail sending them all out, addressing the person by name and attaching the right personalized letter (you were involved in this part, adayzone!)! It corrects for foreign name spelling that is rendered differently in the email address. It works best for email addresses using the last name before the "@" and can now ignore the first name if it is set in front of the last name (i.e. [email protected]). Thank you all very much for the assistance! this was great team effort. I shall post it as soon as I am home, should I add it in here or in another forum (for sharing code)?