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

发布于 2024-09-13 05:31:03 字数 82 浏览 4 评论 0原文

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

I was just wondering how someone would go about finding all the applications that are installed on Mac OS X 10.5 using preferably applescript and output all their application names to a text file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

何必那么矫情 2024-09-20 05:31:03

Mac OS X 下安装的所有应用程序均在 启动服务数据库。

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 将计算所有已注册应用程序的用户可见名称使用 信息命令:

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

All the applications installed under Mac OS X are registered in the Launch Services database.

The Launch Services framework contains a helper shell command lsregister which among other uses can dump the information stored in the Launch Services database. Under Mac OS X 10.5 and 10.6 that command is located in the following folder:

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

Using a few simple grep filters one can extract the full paths of all registered applications:

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

Putting it all together, the following AppleScript will compute the user visible names of all registered applications using the info for command:

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
清浅ˋ旧时光 2024-09-20 05:31:03

There are a few methods in this post, depending on how in-depth you want your search to be. Also not sure if that's exactly the output format you want, but you can probably tweak it for your specific needs.

¢好甜 2024-09-20 05:31:03

我使用 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 扩展名保存脚本,用户将能够双击它。

I use the system_profiler command to get my text. Then you can parse as needed.

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

maybe pipe it to a text file and then use sed ....

Bash commands can be called through applescript if you want to have an application or you can save the script with a .command extension and the user will be able to double-click on it.

情感失落者 2024-09-20 05:31:03

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

For poeple like me using bash scripting to reach their goals here is a bash variant of the script:

#!/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 }'

This gives a list of all apps without the .app extension.

放血 2024-09-20 05:31:03

AsObjC 解决方案

use AppleScript version "2.5" -- EI Capitan and later
use framework "Foundation"
use scripting additions

set plistString to do shell script "system_profiler -xml SPApplicationsDataType"
set dataString to current application's NSString's stringWithString:plistString
set plistData to dataString's dataUsingEncoding:4
set propertyList to current application's NSPropertyListSerialization's propertyListWithData:plistData options:0 format:(missing value) |error|:(missing value)
set allItems to (propertyList's objectAtIndex:0)'s objectForKey:"_items"
set theDictionary to allItems's dictionaryWithValuesForKeys:{"_name", "version", "path", "arch_kind", "obtained_from", "lastModified", "signed_by"}


-- |version| of theDictionary as list  -- versions list
-- |path| of theDictionary as list  -- Posix paths list
-- arch_kind of theDictionary as list -- architecture list
-- obtained_from of theDictionary as list -- developer name list
-- (lastModified of theDictionary) as list -- lastModified dates list 
-- signed_by of theDictionary as list -- software signings list of lists
_name of theDictionary as list -- app names list

注意:我位于已安装应用程序名称列表上方。取消注释相应的代码行以获取版本、Posix 路径(等等)列表。

AsObjC solution:

use AppleScript version "2.5" -- EI Capitan and later
use framework "Foundation"
use scripting additions

set plistString to do shell script "system_profiler -xml SPApplicationsDataType"
set dataString to current application's NSString's stringWithString:plistString
set plistData to dataString's dataUsingEncoding:4
set propertyList to current application's NSPropertyListSerialization's propertyListWithData:plistData options:0 format:(missing value) |error|:(missing value)
set allItems to (propertyList's objectAtIndex:0)'s objectForKey:"_items"
set theDictionary to allItems's dictionaryWithValuesForKeys:{"_name", "version", "path", "arch_kind", "obtained_from", "lastModified", "signed_by"}


-- |version| of theDictionary as list  -- versions list
-- |path| of theDictionary as list  -- Posix paths list
-- arch_kind of theDictionary as list -- architecture list
-- obtained_from of theDictionary as list -- developer name list
-- (lastModified of theDictionary) as list -- lastModified dates list 
-- signed_by of theDictionary as list -- software signings list of lists
_name of theDictionary as list -- app names list

NOTE: I get above the list of installed application Names. Uncomment corresponding code line to get Versions, Posix paths (and so on) list.

倾`听者〃 2024-09-20 05:31:03

System_profiler可以输出json,powershell(osx中的pwsh)可以将其转换为对象。或者将 json(或 xml)保存到文件中。

system_profiler SPApplicationsDataType -json | convertfrom-json |
  % SPApplicationsDataType | ? _name -match slack

_name          : Slack
arch_kind      : arch_arm_i64
lastModified   : 10/17/2023 6:19:47 PM
obtained_from  : mac_app_store
path           : /Applications/Slack.app
signed_by      : {Apple Mac OS Application Signing, Apple Worldwide Developer Relations Certification Authority, Apple Root CA}
version        : 4.34.121

System_profiler can output json, which powershell (pwsh in osx) can turn into objects. Or save the json (or xml) to a file.

system_profiler SPApplicationsDataType -json | convertfrom-json |
  % SPApplicationsDataType | ? _name -match slack

_name          : Slack
arch_kind      : arch_arm_i64
lastModified   : 10/17/2023 6:19:47 PM
obtained_from  : mac_app_store
path           : /Applications/Slack.app
signed_by      : {Apple Mac OS Application Signing, Apple Worldwide Developer Relations Certification Authority, Apple Root CA}
version        : 4.34.121
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文