解决方法
在Mac OS X下安装的所有应用程序都在
Launch Services数据库中注册.
Launch Services框架包含一个helper shell命令lsregister,该命令除其他用途外还可以转储存储在Launch Services数据库中的信息.在Mac OS X 10.5和10.6下,该命令位于以下文件夹中:@H_404_7@
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
使用一些简单的grep过滤器,可以提取所有已注册应用程序的完整路径:@H_404_7@
lsregister -dump | grep --after-context 1 "^bundle" | grep --only-matching "/.*\.app"
总而言之,以下AppleScript将使用info for命令计算所有已注册应用程序的用户可见名称:@H_404_7@
property pLSRegisterPath : "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" set theAppPaths to every paragraph of (do shell script pLSRegisterPath & " -dump | grep --after-context 1 \"^bundle\" | grep --only-matching \"/.*\\.app\"") set theNames to {} repeat with thePath in theAppPaths try copy displayed name of (info for (thePath as POSIX file)) to end of theNames end try end repeat choose from list theNames