I must admit, I've not aliased remote paths myself before, and so my inclination here is to AppleScript a solution.
When retrieving the properties of an alias file through AppleScript, as far as I can tell, if the remote path to which the alias file points cannot be accessed, Finder sets the original item
property for the file (in AppleScript) to missing value
, otherwise this property will contain a Finder reference to the file path of the original item. Therefore, this property seems like our discriminator.
However, you also said that your folder contains thousands of aliases. This isn't a number that Finder loves, and I wouldn't recommend trying to select them all either. Therefore, I've scripted System Events to retrieve the list of alias files from a chosen folder, then invoked Finder to iterate through them one-by-one to test the original item
property and build a list of those aliases with broken links.
set dir to (choose folder)
set dirout to "__null"
set L to {}
tell application "System Events" to set fs to the path of ¬
every file of dir whose kind = "Alias"
with timeout of 600 seconds
tell application "Finder"
repeat with f in fs
tell file f to if not ¬
(its original item exists) ¬
then set end of L to it
end repeat
ignoring application responses
make new folder at dir with properties {name:dirout}
end ignoring
move L to the folder named dirout in dir
end tell
end timeout
The script will ask you to select a directory, which will be the directory containing your alias files. If this is a one-time thing, I'd suggest it might be easier just to run this script from within Script Editor or, if you have it, Script Debugger. There's no point running this from Keyboard Maestro, which I think will slow the execution time down somewhat.
Bear in mind that this will not be a quick process, depending on your computer's processing power and the number of broken alias links that exist (Finder can identify a working alias pretty quickly, but takes a couple of seconds to determine that an alias is broken). It will also likely block Finder in the process, so you should choose a time to execute this script when you won't be wanting to utilise Finder yourself. However, be around during its run, in case the script throws an unexpected error.
When the script is complete, a dialog showing "Done." will pop up, and the broken alias files will be found in a subfolder called "__null"
of the original directory.
Let me know how it goes.