Page 1 of 1

Broken Aliases

PostPosted: Sat May 23, 2009 9:06 am
by bobembry
I use Default Folder X. It can add a folder alias to ~/Library/ Recent Folders for folders accessed through the Open and Save dialogs. Also every time a DMG is mounted it gets added to Recent Folders. When these DMG gets trashed a broken alias remains.

Can Hazel identify these broken aliases and move them to the trash?

Thanks

Bob

Re: Broken Aliases

PostPosted: Tue May 26, 2009 2:26 pm
by Mr_Noodle
There's no built-in way to do this. The only way I can see doing it is via AppleScript. If you know AppleScript and go this route, I suspect you'd have to tell Finder to resolve the alias files for you. I'd google around for snippets if possible.

Re: Broken Aliases

PostPosted: Wed May 27, 2009 4:13 pm
by sjk
I found this simple perl script to resolve alias targets:
Code: Select all
#!/usr/bin/perl

my $path = $ARGV[0];

use Mac::Errors;
use Mac::Files;
use Mac::Resources;
 
my $res  = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
my $link = ResolveAlias($alis);
print "$link \n";

Quick test on my 10.5.7 system:

% perl showaliaspath.pl ~/Desktop/Archive
/Users/Shared/Archive

More than you'd ever want to do with aliases seems possible using the Mac::Files module. :)