HI everyone I’ve not been using AS for a while so I’m a little hazy on it. I need to get a burn folder from another computer via a portable disk onto my computer so I can burn off copies at will. The problem is the files in the burn folders are only aliases and are dotted all over the place and are many. It is taking ages to do this manually so I though I could write a little script to copy the original files that the burn folder points to into a new folder of my choosing whilst still leaving the originals and the alias on the burn folder untouched.
It seems to be a lot harder than I though though can anyone give me any tips on identifying and copying/replacing alias/original files in the finder?
I am still on 10.4.11 if that makes a difference but the computer I am copying from is on 10.5.x
set sourceFolder to choose folder with prompt "choose source folder"
set destinationFolder to choose folder with prompt "choose destination folder"
tell application "Finder"
set allAliases to every alias file of sourceFolder
repeat with oneAlias in allAliases
duplicate (get original item of oneAlias) to destinationFolder
end repeat
end tell
Hi guys, thanks for your replies. Sorry I didn’t respond but I’ve changed my email address since I last logged on and forgot to check the spam folder of my old email address for replies :rolleyes:
Anyway, the situation has change slightly - I have all the burn folders on my computer now, and in the next directory up I have all the original files in another folder (and then in many other folders inside that). The problem I now have is that the aliases in the burn folder still point to the files on the original computer, so when I try to burn or find them using command+R it won’t find them because the folder structure is different.
(NOTE, the files and burn folders came from 10.5.X but are now in my computer running 10.4.11 if that changes anything).
How would I get and CHANGE the path that the alias references? it’s easy to do it one at a time by getting info and then clicking “select new original” but to do this for a few hundred files spread around several folders is very tedious and anyway all I need to do is change the beginning of the path for each file and it should work!
Any ideas much appreciated. I have changed my email address now so I will respond much quicker!
I’ve written a script to replace all aliases with the originals in a folder and all subfolders. Hope this helps.
on run
set assetsFolder to (choose folder with prompt "Select folder...")
replaceAliases(assetsFolder)
end run
on replaceAliases(targetFolder)
tell application "Finder"
set recipeFiles to files of targetFolder
repeat with aFile in recipeFiles
if class of aFile is alias file then -- make sure we are working with an alias file
set originalFile to original item of aFile -- the original file of the alias
set containerFolder to container of aFile -- container folder of alias
move aFile to trash -- delete the alias
duplicate originalFile to containerFolder -- duplicate original to container folder
end if
end repeat
end tell
tell application "Finder" to set theseSubFolders to folders of targetFolder
repeat with tSubF in theseSubFolders
my replaceAliases(tSubF)
end repeat
end makePatches
dbirdz. Welcome to the forum and thanks for the script, which works great.
FWIW, I ran some timing tests to see what impact two edits would have on your script, and the edits reduced the timing result from 8.3 to 6.9 seconds. This was with 25 subfolders each of which contained two alias files. The edits were to use Finder’s entire contents property to get a list of all files in the target folder and to use Finder’s delete command to move the alias files to the trash.
on run
set assetsFolder to (choose folder with prompt "Select folder...")
replaceAliases(assetsFolder)
end run
on replaceAliases(targetFolder)
tell application "Finder"
set recipeFiles to every alias file of entire contents of targetFolder
repeat with aFile in recipeFiles
set originalFile to original item of aFile -- the original file of the alias
set containerFolder to container of aFile -- container folder of alias
delete aFile -- move alias file to trash
duplicate originalFile to containerFolder -- duplicate original to container folder
end repeat
end tell
end replaceAliases