列出所有应用程序 - 输出为文本文件

时间:2010-08-09 21:21:43

标签: macos list text applescript

我只是想知道如何使用优选的Applecript找到Mac OS X 10.5上安装的所有应用程序,并将所有应用程序名称输出到文本文件中。

4 个答案:

答案 0 :(得分:3)

Mac OS X下安装的所有应用程序都在Launch Services数据库中注册。

Launch Services框架包含一个帮助程序shell命令lsregister,除其他用途外,还可以转储存储在Launch Services数据库中的信息。在Mac OS X 10.5和10.6下,该命令位于以下文件夹中:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister

使用一些简单的grep过滤器,可以提取所有已注册应用程序的完整路径:

lsregister -dump | grep --after-context 1 "^bundle" | grep --only-matching "/.*\.app"

总而言之,以下AppleScript将使用info for命令计算所有已注册应用程序的用户可见名称:

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

答案 1 :(得分:1)

this post中有一些方法,具体取决于您希望搜索的深度。还不确定这是否是您想要的输出格式,但您可以根据自己的特定需求进行调整。

答案 2 :(得分:1)

我使用system_profiler命令来获取我的文本。然后你可以根据需要解析。

system_profiler SPApplicationsDataType

...

AppleScript Utility:

  Version: 1.1.1
  Last Modified: 5/18/09 10:34 PM
  Kind: Intel
  64-Bit (Intel): Yes
  Location: /System/Library/CoreServices/AppleScript Utility.app

可能将其传输到文本文件然后使用sed ....

如果你想拥有一个应用程序,可以通过applescript调用Bash命令,或者你可以用.command扩展名保存脚本,用户就可以双击它。

答案 3 :(得分:0)

像我这样的人使用bash脚本来实现他们的目标是脚本的bash变体:

#!/usr/bin/env bash

path='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support'
$path/lsregister -dump | grep -A 1 "^bundle" | grep --only-matching "/.*\.app" | awk -F "/" '{ print $NF }' | awk -F "." '{ print $1 }'

这会列出所有没有.app扩展名的应用。