This processes through the Finder selection and creates a folder on your desktop into which the broken alias files will be moved:
property dirout : "__null_aliases__"
set fs to {}
set L to {}
tell application "Finder"
repeat with f in (get selection)
if f's class = folder then set fs to fs & ¬
(every alias file in f as alias list)
end repeat
with timeout of 600 seconds
repeat with f in fs
try
f's original item
on error
set end of L to f's contents
end try
end repeat
ignoring application responses
make new folder at desktop ¬
with properties ¬
{name:dirout}
end ignoring
move L to the folder named dirout
end timeout
end tell
Alternatively, the one that follows is similar to the initial script, but performs a deep search of nested folders. Please consider the depth of the directory tree. For example, selecting your home folder would probably be a bad idea if you want to stay sane. The seemingly innocuous desktop folder is the other location I recommend against doing a deep search, since it tends to contain a link to Macintosh HD
(or whatever you might have renamed your local hard disk to), which will obviously result in every single file and folder on your entire system being searched.
property dirout : "__null_aliases__"
set dir to (choose folder)
set L to {}
tell application "Finder"
set fs to every alias file in the entire contents of dir as alias list
with timeout of 600 seconds
repeat with f in fs
try
f's original item
on error
set end of L to f's contents
end try
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 timeout
end tell