开发者

How to query target of all Finder aliases?

Mac OSX 10.6

I've got some aliases that are pointing to the wrong volume. I'd like to search my whole hierarchy for such aliases. They're aliases, not symlinks, so I can't just do find / -type l -ls | grep badVolumeName.

It seems that aliases have a com.apple.ResourceFork, but querying this with xattr gives me binary data. Is there a way to dum开发者_如何学Pythonp the target of the alias as text so I can grep for the bad volume name? Or what's another way to do this?


To find alias files you can make use of this answer on StackOverflow. First, create a script is_alias.sh:

#! /bin/bash
[ "$(mdls -raw -name kMDItemKind "$1")" = "Alias" ]

and then run

find . -type f -exec ./is_alias.sh {} \; -print

Getting the path of an alias seems quite difficult.

Someone has posted a solution using MacPerl, but as I do not have MacPerl I haven't tested this and don't know whether it works.

There is a similar question on AskDifferent, with several different suggestions, but none of them seem to actually solve the problem. The Applescript answer is okay, but the key operation, getting the "original item" of an alias file, doesn't seem to work for broken aliases.

You can also take a look at this question which might have some Cocoa solutions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜