need to correct where 1000's of Aliases are pointing

Discussion in 'macOS' started by hak7, Jan 9, 2017.

  1. hak7

    hak7 MDL Novice

    Dec 21, 2016
    3
    0
    0
    #1 hak7, Jan 9, 2017
    Last edited: Jan 9, 2017
    Hi,
    I used Aperture for several years, and now use Lightroom.
    The way I exported my pictures from Aperture generated a lot of duplicates.

    I am using TidyUp to deduplicate, and it can generate Aliases for me.
    The issue is I used a local SSD connected to my mac running El Capitan,
    Then I moved the files to my NAS thinking the Aliases would change as
    they were moved, but it appears they only automatically change
    if they stay on the same disk (volume).

    Here is a sample of the alias referencing the old location:

    /Volumes/kerryToDeDup/Lightroom2/0025.JPG

    and here is a sample on an alias generated right on the NAS
    which is how I need all of them to be like:

    /Volumes/ps/Lightroom Files/0533.JPG

    almost all of the pictures are in subfolders, like

    /Volumes/kerryToDeDup/Lightroom2/at the park 2015-07-04/dsc0001.JPG
    or now corrected to
    /Volumes/ps/Lightroom Files/at the park 2015-07-04/dsc0001.JPG

    I moved thousands of files before I realized the problem.
    Is there a program to correct the alias' reference,
    or could someone put together a script that will automatically also look in subfolders?

    basically any alias that starts with
    /Volumes/kerryToDeDup/Lightroom2/

    has to be corrected to
    /Volumes/ps/Lightroom Files/


    Thanks for your help and all the best to you in 2017!

    Kerry
     
  2. hak7

    hak7 MDL Novice

    Dec 21, 2016
    3
    0
    0
    #2 hak7, Jan 9, 2017
    Last edited by a moderator: Apr 20, 2017
    (OP)
    OK, I'm learning applescript through some videos. here's a script I copied hours ago, that I am trying to change for my situation.
    I'll keep updating it as I learn more. I will refind where I got the original of this script and give a reference also.
    Here is round 1 ! Sorry, just realized I don't know how to post this as formatted text yet. Will attach a file. I tried uploading a text file (3k size) but it is not saving - I guess I'm too new a user?



    Code:
    tell application "Finder"
        set folder_items to the selection
    end tell
    
    repeat with i from 1 to the count of folder_items
        set this_item to (item i of folder_items) as alias
        set this_info to info for this_item
    
        if class of this_item is alias then
            tell application "Finder"
                set original_file to original item of this_item
                set this_alias_file_name to displayed name of this_item
                set container_folder to container of this_item
    
                set the_path to the POSIX path of (original_file as alias)
                set new_path to my replaceText("/Volumes/kerryToDeDup/Lightroom2/", "/Volumes/ps/Lightroom Files/", the_path)
    
                move this_item to trash
                try
                    make new alias file at container_folder to (POSIX file new_path) with properties {name:this_alias_file_name}
                on error errMsg number errorNumber
                    if errorNumber is -10000 then -- new original file not found, try relinking to old
                        try
                            make new alias file at container_folder to (POSIX file the_path) with properties {name:this_alias_file_name}
                        on error errMsg number errorNumber
                            if errorNumber is -10000 then -- old original not found. link's dead Jim
                                display dialog "The original file for alias " & this_alias_file_name & " was not found."
                            else
                                display dialog "An unknown error occurred:  " & errorNumber as text
                            end if
                        end try
                    else
                        display dialog "An unknown error occurred:  " & errorNumber as text
                    end if
                end try
            end tell
        end if
    end repeat
    
    on replaceText(find, replace, subject)
        set prevTIDs to text item delimiters of AppleScript
        set text item delimiters of AppleScript to find
        set subject to text items of subject
    
        set text item delimiters of AppleScript to replace
        set subject to "" & subject
        set text item delimiters of AppleScript to prevTIDs
    
        return subject
     
  3. hak7

    hak7 MDL Novice

    Dec 21, 2016
    3
    0
    0
    Thanks to Tito for setting the code up in a spoiler box.

    I won't be able to get back to this to finish it until near the 27th of January, maybe over that weekend (so about 10 days from now).
    Any one who already knows how to finish this may feel free to do so!

    What I am seeking to have this script do is
    1. Start in a given folder.
    2. Check in that same folder and fix broken aliases.
    3. Check any subfolder of the starting folder, and fix any broken aliases in those folders also.

    In my case, I never have a duplicate (or so few I am not concerned) outside of the starting folder.

    for example:

    -Vacation 2016
    ----- at the beach
    ----- hang gliding
    ----- horseback riding

    -Vacation 2015
    . . . and so on

    Thanks,
    Kerry