2015-06-15 50 views
0

我真的很希望有人能幫助我解決這個問題。我最近從一個mac移到另一個,並做了一個乾淨的安裝。我有幾個有數百個別名的文件夾(你怎麼說別名的複數?)...如何在遷移後在mac上修復100個別名?

原始文件路徑是「/ Volumes/Media Drive/Ableton/Warped Tracks /」,而新路徑需要成爲「/用戶/ joel /音樂/ Ableton項目/扭曲曲目」

我看到如何解決他們一次一個,但這將需要幾個小時。我試過這個applescript,但沒有運氣: https://apple.stackexchange.com/questions/2656/how-do-i-fix-failed-aliases

任何人都可以給我一個更好的applescript或另一種解決方案嗎?正如我所提到的,我試過這個applescript:

tell application "Finder" 
    set these_items to the selection 
end tell 

repeat with i from 1 to the count of these_items 
    set this_item to (item i of these_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/Media Drive/Ableton/Warped Tracks/", "https://stackoverflow.com/users/joel/Music/Ableton Projects/Warped Tracks", 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 
end replaceText 

任何幫助將不勝感激。

編輯:我認爲對我來說,蘋果筆記本電腦的問題是,我有更多的文件夾下的路徑都是不同的,每個包含單獨的別名文件。 IE: 「/ users/joel/Music/Ableton Projects/Warped Tracks/Folder A/file.alias」,/ users/joel/Music/Ableton Projects/Warped Tracks/Folder B/file2.alias「等等,等等

+0

[看起來有人在這裏解決了這個問題](http://apple.stackexchange.com/a/86549) – davidcondrey

+0

@davidcondrey,謝謝你的回覆。這是我上面發佈的鏈接。在答案中提供的applescript對我來說不起作用 - 我應該說,applescript不適合我,我不知道Ruby的第一件事。 : -/ – Joel

+1

你還有原始卷「/ Volumes/Media Drive/Ableton/Warped Tracks /」以及別名指向的所有原始文件嗎? –

回答

0

我有同樣的問題,年前(2個媒體中心之間轉移),和我做了這個程序:它要求的文件夾都碎別名都然後試圖找到重建他們再次原始路徑

的東西。當鏈接被破壞時,任何有關別名的applescript指令都會給出錯誤信息,因此當鏈接已損壞時,您必須使用Finder信息窗口無誤地讀取原始路徑: (此程序假定原始文件名是唯一的)

-- Select main folder 
tell application "Finder" to set Mon_Dossier to ((choose folder with prompt "Select top folder:" without invisibles) as alias) as string 

-- repair alias in this folder and all subsequent folders (entire contents) 
tell application "Finder" to set Mes_Alias to every file of entire contents of folder Mon_Dossier whose class is alias file 
-- loop on each alias of the folder 
repeat with Mon_Alias in Mes_Alias 
    -- found the original file path of Mon_Alias 
    -- try first with standard alias call 
    set F_Source to "" 
    try 
     tell application "Finder" to set F_Source to original item of Mon_Alias 
    end try 
    if F_Source is "" then 
     -- the link to original file is broken, then use on windows info method 
     set F_Source to Origine_Alias(Mon_Alias) 
     set F_Original to Decompose(F_Source) 
     -- no need to look original file as is, becuase the link is broken (path changed ?) 
     -- then directly search for the same file without extension 
     set Cible to ((chemin of F_Original) as string) & ((Nom of F_Original) as string) 
     tell application "Finder" 
      if exists file Cible then 
       -- file is found without extension 
       -- then delete alias and create new alias with same name and in same folder 
       set A_Nom to name of Mon_Alias 
       set A_Dossier to folder of Mon_Alias 
       delete Mon_Alias 
       set Nouvel_Alias to make alias to Cible at A_Dossier 
       set name of Nouvel_Alias to A_Nom 
      else 
       SLog("Alias=" & (Mon_Alias as string) & "  File not found=" & Cible) 
      end if 
     end tell 
    else 
     -- the alias link is still valid : nothing to do ! go to next alias.. 
    end if 
end repeat 
-- end main program 


-- sub routine to find passe of broken link (original path/file can't be found) 
-- the result is a unix path like folder/sub_folder/file 
on Origine_Alias(F_Alias) 
    set R to "" 
    tell application "Finder" to open information window of file (F_Alias as text) 
    tell application "System Events" to tell process "Finder" to set R to value of static text 19 of scroll area 1 of front window 
    tell application "Finder" to close front window 
    return R 
end Origine_Alias 


-- sub routine to extract, from unix file path, the path, the file name and its extension: result is sent back in a record 
-- Warning : we can't use "Posix file of" becuase the path and the file are non longer valid ! (then Posix gives error) 
on Decompose(Local_F) 
    --search the first "." from right to find extension 
    set X to length of Local_F 
    repeat while (character X of Local_F is not ".") and (X > 0) 
     set X to X - 1 
    end repeat 
    if X > 0 then 
     set L_Ext to text (X + 1) thru (length of Local_F) of Local_F 
     set Local_F to text 1 thru (X - 1) of Local_F 
    else 
     L_Ext = "" -- "." not found, then no extension ! 
    end if 
    -- search first "/" from the right to extract file name 
    set X to length of Local_F 
    repeat while (character X of Local_F is not "/") 
     set X to X - 1 
    end repeat 
    set L_Nom to text (X + 1) thru (length of Local_F) of Local_F 
    set Local_F to text 1 thru (X) of Local_F 
    try 
     set L_Chemin to POSIX file Local_F 
    end try 
    return {chemin:L_Chemin, Nom:L_Nom, Ext:L_Ext} 
end Decompose 

-- sub routine log (text log file on desktop) 
on SLog(msg) 
    set the my_log to ¬ 
     ((path to desktop) as text) & "My_logfile.txt" 
    try 
     -- open file. create it if not yet exist 
     open for access file the my_log with write permission 
     -- add text at end of file 
     write (msg & return) to file the my_log starting at eof 
     close access file the my_log 
    on error 
     try 
      close access file the my_log 
     end try 
    end try 
end SLog 
相關問題