Hi Everyone,
This is my first post here.
Would something like the following be possible with an AppleScript on a Finder window selection?
• Manually search through the Finder for terms using “name matches”
• Manually select from returned search items
• The manual selection includes 1 folder and various # of aliases with varying names
• The script then is executed by the user, using the above manual selection
• The script mimics setting the “Select New Original” path for all aliases to the singular selected folder path, or re-creates aliases at their current location and with same name and pointing to the singular folder in selection.
• Repeat the entire process as needed
My problem is I have many aliases that need re-associated with various original folders. The aliases are broken coming from an older macOS and do not point to the correct original folder so I need to manually Get Info > “Select New Original” or manually remake them. So I was wondering if I could do a search in the finder (using “name matches”) to get a list of these related folder & aliases and then use these user selected results within a script to resolve the alias paths back to the singular actual folder? I was hoping I could just change the original path of the aliases using “set original item” to match the manual process when using “Get Info > Select New Original” without having to delete and remake all the aliases?
Generic Example: search term = Original Folder
• Original Folder (actual folder)
• Original Folder 1 alias
• Original Folder 2 alias
• Original 3 Folder alias
• Original Blah Folder alias
• Blah Original Folder alias
• Blah Original Blah Folder alias
The above would be the user selection from the returned search. The reason I mention just user selected specific items (just the specific folder + relative aliases) from the search query is because there might also be other related files returned in the search also like other folders, aliases, .txt, .webloc, .zip, .img, etc. So I would need to manually select the relative folder + aliases that I want to target in the script. I think due to variables involved doing a manual selection from the returned search results and using that selection within the script would be easier and would still save a lot of clicks verse doing everything manually to fix the aliases.
I have many instances similar to the above example, the number of aliases derived from the original can vary its not a set number and their names can slightly vary also aside from including the key search terms. So I was hoping through a script that I could target these specific returned finder search items (just the folder + associated aliases) and have the script basically mimic the “Select New Original” to the singular folder path of the selection for all the aliases?
I’ve found various threads on the forum and elesewhere given my lack of understanding which are possibly relative that I’ve tried to use to cobble something together. Though I’m really not confident regarding my described scenario as I am not so well versed in AppleScript at this level. I sure wouldn’t want to mess things up further than what they already are regarding old broken aliases by trying to cobble something together and break things further or completely screw up the file system :—).
Below are some of my failed attempts at trying to cobble something together which should easily show my lack of understanding unfortunately. Obviously nothing is working as expected to completion in my isolated tests. I feel in some small way I’m blindly on the right track but in reality I’m probably way off which could easily be the case given my lack of knowledge. With some of my attempts even when other things are sorted out, it seems maybe I will need to use a different loop other than a simple repeat given some “display” feedbacks don’t seem to pair up correctly? Again I’m rather confused in my attempts.
Here is one of my failed attempts at trying to use “set original item”.
tell application "Finder"
set selItems to selection
repeat with curItem in selItems
if class of curItem is folder then
set folderPath to POSIX path of (curItem as alias)
display dialog folderPath
end if
end repeat
set selItems to selection
repeat with curItem in selItems
if class of curItem is alias file then
-- set original item of file curItem to file folderPath
-- set original item of alias file curItem to folderPath
-- set original item of file curItem to POSIX file folderPath
-- set originalFile to the original item of (file folderPath)
-- set original item of file curItem to folderPath
end if
end repeat
display dialog "Done"
end tell
Here is one of my failed attempts at remaking the aliases at their current location.
tell application "Finder"
set selItems to selection
repeat with curItem in selItems
if (kind of curItem) is "folder" then
set folderPath to POSIX path of (curItem as alias)
-- display dialog folderPath -- Display
end if
end repeat
repeat with currentFile in selItems
if (kind of currentFile) is "alias" then
set currentAliasName to displayed name of currentFile
set aliasPath to currentFile as alias
set currentAliasFile to file currentAliasName of folderPath as alias
tell application "Finder"
delete currentFile
make new alias file at folder aliasPath to currentAliasFile
end tell
end if
end repeat
end tell
Both probably don’t make much sense given at this point I’m very confused myself with all the attempts and changes I’ve tried thus far. But I wanted to show that I’m earnestly trying but I’m seriously confused and stuck in my efforts to accomplish this. So I’m seeking assistance here.
I’m really hoping something could be accomplished as this would really help me automate some the otherwise brutal manual process of relinking or remaking all these broken aliases. I’m hoping such a script could work from the selection in the search window because it needs to be generic enough for various inputs of original folder + # of aliases. I have a list of the all the unique search terms I will need to search for.
The more I search this forum, stackoverflow, etc., hoping to cobble something together the more confused I get. Plus I’m concerned that I may mess up my folders further that’s why I’ve created an isolated test hoping to create a working script. Any suggestions, input, insight or overall help is very much welcome from anyone.
Sorry for the huge write up I hope it makes some sort of sense.
Thanks everyone !
LL