1

I have a file structure for photos which is Year >Date, then within each date folder I have RAW images plus a folder named 'jpg', which contains jpg copies of the RAW files.

I need to move the jpg folders to a new location, but rename them first, to the name of the first file in the folder, which is always a descriptor, so from 'jpg' to 'Jack and Jill-1.jpg'

Once I've renamed all of the folders, (10 years of photos), I can strip out the extension and number leaving me with a folder called 'Jack and Jill'

I'm an absolute newbie with AppleScript, but have a script that works in a sense as in it performs perfectly on a test folder on my Desktop, but I can't get it to run on a mounted drive, or my network drive.

The script I've butchered is possibly carrying excess baggage and can be trimmed down, but I'm really looking for function over form as it only has to run once.

The script is purely for the initial rename, I have the extension removal side working okay via Better Rename.

tell application "Finder"
    -- Defining Pro Folders 
    set pro_folder to folder POSIX file "/Users/JeffOliver/Desktop/photo"
    set all_pro_folders to every folder of pro_folder

    -- Iterate through folders and check if folder name is greater than one character
    repeat with parent_folder in all_pro_folders
        set counter to 0 -- reset a counter variable we use for the end of the name 
        set child_folders to every folder of parent_folder
        repeat with current_folder in child_folders
            set fold_name to the name of current_folder
            log (fold_name)
            if (the length of fold_name < 8) then -- this will allow names > 9  
                set counter to counter + 1 -- increment the counter every time we find valid folder
                set new_name to name of first file of current_folder
                log (new_name)
                set the name of current_folder to new_name
            end if
        end repeat
    end repeat
end tell

Any help in getting this to work on a network drive is greatly appreciated

  • Does it have to be AppleScript (e.g. because you use this as a learning opportunity) or would a shell script be acceptable as well? – nohillside Apr 21 '17 at 9:36
  • And related to the problem: how do you determine "the first file in the folder"? Is this the first file showing when sorted alphabetically in Finder? – nohillside Apr 21 '17 at 9:37
  • A shell script would be fine, at my level I just thought AS would be easier to get my head around. Yes. exactly that, the first file alphabetically in Finder, the only files in there are going to be called 'Jack and Jill-xxx' 1 to 500+, so it doesn't make too much difference to my objective, though it may cause a few issues with the rename if the number of final digits vary across the folders – Jeff Oliver Apr 21 '17 at 10:08
  • It would be helpful if you would add a screenshot of the hierarchal folder structure with a target file highlighted. Also, is the network drive mounted at /Volumes as one might expect? – user3439894 Apr 21 '17 at 15:30
  • Screenshot is flic.kr/p/TSTT18. Although the NAS isn't mounted, I have a folder within it that is mounted as a volume I guess afp://MediaDrive._afpovertcp._tcp.local/Photos – Jeff Oliver Apr 21 '17 at 17:20

You must log in to answer this question.

Browse other questions tagged .