Hello,
I have a lot of journals collected from the torrent trackers. The files of the journals have a different and sometimes confusing names, which can not be renamed so as not to disrupt the seeding in the torrent client.
I create a journal’s folder in the ~ / Documents folder and make aliases to the originals files.
This makes easy to use , and read journals.
Then I rename all files (aliases) to the same type name. This is a sample folder (78Kb)
There is one example (green color)
/Home/Journals/ Family Handyman-2003-10 # 442.pdf
is alias to (clik on it and Show Original)
/Home/Torrents/Handyman-442.pdf.
But there comes a time, and the seading should be completed and I want to replace all aliases to the original files, and retain the new name, which I gave to alias.
Now I use this script -
tell application "Finder"
set theSelection to selection -- get the selected files in the front finder window
repeat with aFile in theSelection -- loop through the selected files
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
move originalFile to containerFolder -- duplicate original to container folder
end if
end repeat
end tell
It works well but retains the original name.
I need also to rename . How?
Thanks in advance !
tell application "Finder"
set theSelection to selection -- get the selected files in the front finder window
repeat with aFile in theSelection -- loop through the selected files
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 alias_name to name of aFile
set containerFolder to container of aFile -- container folder of alias
move aFile to trash -- delete the alias
tell application "Finder" to set name of originalFile to alias_name
move originalFile to containerFolder -- move original to container folder
end if
end repeat
end tell
Events+Replies:
tell application "Finder"
get selection
--> {alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra"}
get class of alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra"
--> alias file
get original item of alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra"
--> document file "ORIG.jpg" of disk "Extra"
get name of alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra"
--> "Alias_ORIG.jpg"
get container of alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra"
--> folder "Folder" of disk "Extra"
move alias file "Alias_ORIG.jpg" of folder "Folder" of disk "Extra" to trash
--> alias file "Alias_ORIG 17-33-29.jpg" of folder "501" of folder ".Trashes" of disk "Extra"
--> error number 0
set name of document file "ORIG.jpg" of disk "Extra" to "Alias_ORIG.jpg"
--> "Alias_ORIG.jpg"
move document file "ORIG.jpg" of disk "Extra" to folder "Folder" of disk "Extra"
--> error number -1728 from document file "ORIG.jpg" of disk "Extra"
Result:
error "Finder got an error: Can't get document file \"ORIG.jpg\" of disk \"Extra\"." number -1728 from document file "ORIG.jpg" of disk "Extra"
The Finder uses name references (eg. ‘file “ORIG.jpg” of .’), so if you change the name of a file, any existing reference to it (ie.the value of ‘originalFile’) will no longer work. That’s why you’re getting an error in the ‘move’ line. In your case, it would be easiest to move the file first and then rename the result:
tell application "Finder"
set theSelection to selection -- get the selected files in the front finder window
repeat with aFile in theSelection -- loop through the selected files
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 alias_mame to name of aFile
set containerFolder to container of aFile -- container folder of alias
move aFile to trash -- delete the alias
set originalFile to (move originalFile to containerFolder) -- move original to container and get a reference to it there.
set name of originalFile to alias_mame -- rename original.
end if
end repeat
end tell