Macos 在列表中存储字符串时Applescript返回错误

Macos 在列表中存储字符串时Applescript返回错误,macos,applescript,Macos,Applescript,我编写了一个简单的脚本,找出目前机器上有多少个活动进程正在运行,并将每个进程的路径作为字符串输出到一个数组中 这是我的代码(它实际上没有合法的功能,我只是尝试不同的方法来看看applescript是如何工作的): 以下是当我点击run时applescript编辑器返回的错误: System Events got an error: Can’t set list {0} to "Macintosh HD:System:Library:CoreServices:loginwindow.app:".

我编写了一个简单的脚本,找出目前机器上有多少个活动进程正在运行,并将每个进程的路径作为字符串输出到一个数组中

这是我的代码(它实际上没有合法的功能,我只是尝试不同的方法来看看applescript是如何工作的):

以下是当我点击run时applescript编辑器返回的错误:

System Events got an error: Can’t set list {0} to "Macintosh HD:System:Library:CoreServices:loginwindow.app:".
什么是我没有错?

试试:

tell application "System Events" to set myprocess to files of processes

您可以从重复循环生成列表,如下所示:

set paths to {}
tell application "System Events"
    set activeProcess to processes
    repeat with n from 1 to count activeProcess
        set end of paths to (file of item n of activeProcess as text)
    end repeat
end tell
set paths to {}
tell application "System Events"
    set activeProcess to processes
    repeat with aProcess in activeProcess
        set end of paths to (file of aProcess as text)
    end repeat
end tell
或者像这样:

set paths to {}
tell application "System Events"
    set activeProcess to processes
    repeat with n from 1 to count activeProcess
        set end of paths to (file of item n of activeProcess as text)
    end repeat
end tell
set paths to {}
tell application "System Events"
    set activeProcess to processes
    repeat with aProcess in activeProcess
        set end of paths to (file of aProcess as text)
    end repeat
end tell

哇,这不是很直观;Applescript应该是业余爱好者友好的:(谢谢你的帮助!