0

如何使用 AppleScript 或 Python 列出我的 Mac 上可用的所有应用程序?
请帮我。

4

1 回答 1

1

检查以下 AppleScript:

set theResult to every paragraph of (do shell script "mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c' | sort")
set systemApps to {}
set applicationsApps to {}

repeat with i from 1 to number of items in theResult
    set end of systemApps to item i of theResult
    if item i of theResult contains "/Applications/" then
        set end of applicationsApps to item i of theResult
    end if
end repeat

systemApps列表包含系统上的应用程序,例如:

{
"/Applications/Address Book.app",
"/Applications/Calculator.app",
"/Library/Image Capture/Devices/EPSON Scanner.app", 
"/Library/Little Snitch/Little Snitch Network Monitor.app",
"/Library/Scripts/ColorSync/Show Info.app",
[....]
}

applicationsApps列表包含应用程序文件夹中的应用程序,例如:

{
"/Applications/Address Book.app", 
"/Applications/App Store.app", 
"/Applications/Automator.app", 
"/Applications/Calculator.app",
"/Applications/Utilities/Activity Monitor.app"
[....]
}

上面的脚本基于 Ross 的脚本(参见Mac OSX Hints Forums):

set appString to do shell script "mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c' | sort"
set appList to every paragraph of appString
set theReport to ""
repeat with i from 1 to number of items in appList
set theItem to item i of appList
set theApp to (a reference to POSIX file theItem)
set fileInfo to info for theApp
set versionInfo to long version of fileInfo
if versionInfo is missing value then set versionInfo to " "
set theReport to theReport & theItem & " " & versionInfo & return
end repeat
theReport
于 2012-09-04T11:04:52.820 回答