1

I wrote a simple script that finds out how many active processes are running on the machine right now, and outputs the paths of each one into an array as a string.

Here's my code (it really has no legitimate function, I'm just trying to try different things to see how applescript works):

tell application "System Events"
  set activeProcess to number of process
  set paths to {0}
  repeat with n from 1 to activeProcess
    set last item of list paths to (file of process n as string)
  end repeat
end tell

And here's the error applescript editor returns when I hit run:

System Events got an error: Can’t set list {0} to "Macintosh HD:System:Library:CoreServices:loginwindow.app:".

What am I don't wrong?

1 Answer 1

2

Try:

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

or

set AppleScript's text item delimiters to linefeed
tell application "System Events" to set myprocess to paragraphs of (files of processes as text)
set AppleScript's text item delimiters to {""}

You can build a list from a repeat loop like this:

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

or like this:

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
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that's not very intuitive; and Applescript is supposed to be amateur friendly :( Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.