Broken Aliases

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Broken Aliases 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?


Posts: 2
Joined: Sat May 23, 2009 8:43 am

Re: Broken Aliases 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.
Site Admin
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Broken Aliases Wed May 27, 2009 4:13 pm • by sjk
I found this simple perl script to resolve alias targets:
Code: Select all

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 ~/Desktop/Archive

More than you'd ever want to do with aliases seems possible using the Mac::Files module. :)
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Return to Tips & Tricks - DO NOT POST QUESTIONS