2012-09-06 93 views
0

我执行AppleScript中的终端命令“system_profiler SPApplicationsDataType”以获取MAC中已安装的应用程序,我需要解析输出,请解释如何通过Apple脚本或Python实现它。在Applescript中执行终端命令

+0

您是否认为答案有用?你没有接受任何你的问题的答案。你应该学会回馈给SO。 –

回答

0

在Python中,你可以使用子 -

http://docs.python.org/library/subprocess.html

具体来说,check_output方法:http://docs.python.org/library/subprocess.html#subprocess.check_output

所以你只需使用:

output = subprocess.check_output(["system_profiler", "SPApplicationsDataType"]) 
print output # or do something else with it 

你的命令会分解成一个数组,每个争论的一个元素发言:。

在AppleScript的,你可以这样做:

set textReturned to (do shell script "system_profiler SPApplicationsDataType") 

tell application "TextEdit" 
    activate 
    make new document at the front 
    set the text of the front document to textReturned 
end tell 

这将运行命令和输出转储到文本编辑。

+0

感谢您的答复其工作正常..你有什么想法如何自动安装下载的应用程序使用AppleScript或Python的过程?如果有,请告诉我。 – user1648855

+0

你需要对此做一些进一步的研究。 :)(另外,如果答案是正确的,那么请接受它是正确的!) –