列出所有应用程序 - 输出为文本文件
我只是想知道如何使用最好的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Mac OS X 下安装的所有应用程序均在 启动服务数据库。
Launch Services 框架包含一个辅助 shell 命令
lsregister
,该命令除其他用途外还可以转储存储在 Launch Services 数据库中的信息。在 Mac OS X 10.5 和 10.6 下,该命令位于以下文件夹中:使用一些简单的 grep 过滤器,可以提取所有已注册应用程序的完整路径:
将它们放在一起,以下 AppleScript 将计算所有已注册应用程序的用户可见名称使用 信息命令:
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:Using a few simple grep filters one can extract the full paths of all registered applications:
Putting it all together, the following AppleScript will compute the user visible names of all registered applications using the info for command:
这篇文章,取决于您希望搜索的深度。也不确定这是否正是您想要的输出格式,但您可以根据您的特定需求对其进行调整。
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.
我使用 system_profiler 命令来获取我的文本。然后就可以根据需要进行解析了。
...
也许将其通过管道传输到文本文件,然后使用 sed ....
如果您想要一个应用程序,则可以通过 applescript 调用 Bash 命令,或者您可以使用 .command 扩展名保存脚本,用户将能够双击它。
I use the system_profiler command to get my text. Then you can parse as needed.
...
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.
对于像我这样使用 bash 脚本来实现目标的人来说,这里是脚本的 bash 变体:
这给出了所有不带 .app 扩展名的应用程序的列表。
For poeple like me using bash scripting to reach their goals here is a bash variant of the script:
This gives a list of all apps without the .app extension.
AsObjC 解决方案:
注意:我位于已安装应用程序名称列表上方。取消注释相应的代码行以获取版本、Posix 路径(等等)列表。
AsObjC solution:
NOTE: I get above the list of installed application Names. Uncomment corresponding code line to get Versions, Posix paths (and so on) list.
System_profiler可以输出json,powershell(osx中的pwsh)可以将其转换为对象。或者将 json(或 xml)保存到文件中。
System_profiler can output json, which powershell (pwsh in osx) can turn into objects. Or save the json (or xml) to a file.