I have a ridiculously large media library, spread across multiple drives. By way of example: drive X, drive Y and drive Z all contain TV Shows directories, and trying to remember which drive's TV Shows directory contains which actual television show is a hassle I'm too lazy to put up with.
I wanted a global TV Shows folder containing the content of each individual drive's own TV Shows folder. Using Smart Folders or aliases presented a few drawbacks, as a lot of applications (not to mention other operating systems) don't understand them, so creating symbolic links (symlinks) was the best option.
The following AppleScript creates symlinks into a single folder from multiple sources
-- Gets the folder list of any number of specified source directories, and creates matching symlinks for each in a single specified directory.
-- Written by Dave Chevell, 2nd of May, 2010. Yay me.
-- The sourceList variable contains the list of folders from which to source your symlinks. As you can see in the following example, they must be separated by commas and contained by "double quotes"
set sourceList to {"/Volumes/Disk X/TV Shows/", "/Volumes/Disk Y/Television shows/", "/Users/Dave/Media/TV Shows/", "/Volumes/Disk Z/video/tvshows/"}
-- The destinationFolder variable is where your symbolic links will be created. The actual folder must exist
set destinationFolder to "/Users/Dave/Desktop/TV Shows/"
-- Whether or not you end your sources or your destination folder with a forward slash, the script accounts for it by adding an extra one. This appears to work without issue (OS X 10.6.3)
repeat with currentSource in sourceList
tell application "Finder"
set sourceFolders to get name of folders of folder (currentSource as POSIX file)
repeat with currentFolder in sourceFolders
-- Even if your sourceList or destinationFolder variable entries end in a forward slash, adding another forward slash in this next step "just in case" still appears to work (tested only on OS 10.6.3)
set fromPath to currentSource & "/" & currentFolder
set toPath to destinationFolder & "/" & currentFolder
-- Escape out characters the terminal does not like in file paths.. for some reason making strings "quoted form of" doesn't work with symlinks, so we have to parse each path and add escape characters instead. New escape characters can be added to the illegalChars variable. They must be separated by commas and contained by "double quotes"
set illegalChars to {" ", "&", "'"}
repeat with delimChar in illegalChars
if fromPath contains delimChar or toPath contains delimChar then
set AppleScript's text item delimiters to delimChar
set the pathText to every text item of fromPath
set AppleScript's text item delimiters to the "\\" & delimChar
set fromPath to the pathText as string
set AppleScript's text item delimiters to delimChar
set the pathText to every text item of toPath
set AppleScript's text item delimiters to the "\\" & delimChar
set toPath to the pathText as string
end if
end repeat
-- Finally, create the damned link. "Try" is used so we can skip errors about existing symlinks
try
do shell script "ln -s " & fromPath & " " & toPath
end try
end repeat
end tell
end repeatMac OS X Hints
http://hints.macworld.com/article.php?story=20100502015718443