【问题标题】:List all applications - output as text file列出所有应用程序 - 输出为文本文件
【发布时间】:2010-08-09 21:21:42
【问题描述】:

我只是想知道有人会如何查找安装在 Mac OS X 10.5 上的所有应用程序,最好使用 applescript 并将它们的所有应用程序名称输出到一个文本文件。

【问题讨论】:

    标签: macos list text applescript


    【解决方案1】:

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

    启动服务框架包含一个辅助 shell 命令lsregister,除其他用途外,它还可以转储存储在启动服务数据库中的信息。在 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
    

    【讨论】:

    • 有没有办法做到这一点,这样它就不会给我完整的路径,而只是给我应用程序的名称?不过还是谢谢你的回答,
    • @Taylor:我已经更新了脚本。现在它计算每个注册应用程序的用户可见名称。
    【解决方案2】:

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

    【讨论】:

    • 糟糕:找不到请求的页面。
    【解决方案3】:

    我使用 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 扩展名保存脚本,然后用户可以双击它。

    【讨论】:

    • 这似乎比lsregister 方法干净得多,但速度要慢一些。
    【解决方案4】:

    对于像我这样使用 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 扩展名的应用。

    【讨论】:

    • 更简单,更快:)。
    猜你喜欢
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    相关资源
    最近更新 更多