something like this, but there is certainly a more sophisticated solution
set p to paragraphs of (do shell script "ps -Acr -o %cpu,command")
set the_list to {}
repeat with i from 3 to count p
copy word 1 of item i of p to end of the_list
copy text from words 2 to -1 of item i of p as Unicode text to end of the_list
end repeat
do shell script "/bin/ps -Acr -o %cpu,command | /usr/bin/ruby -ne 'STDIN.readlines.each {|thisLine| puts thisLine.strip.sub(\" \", \"\\n\")}'"
set psList to paragraphs of result
this is too vague to know if the percentage should be separated.
you stalking me bruce?:lol:
EDIT: on rereading, i did not notice this:
easy enough. change one word:
set the_list to do shell script "ps -Acr -o %cpu,command | sed 1d | sed 's/^ *//'"
set psList to words of result
but i still think you are crossing a line bruce. why not suggest this one word change? surely you could have. PM me directly if you have a personal problem with me. i’m sure we can work it out.
SECOND EDIT: i’m seeing a further problem with this. perhaps you are not stalking. i’ll ponder and repost. apologies if i’m out of line here.
set Stats to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
repeat with I in paragraphs of (do shell script "ps -Acr -o %cpu,command | sed 1d | sed 's/^ *//'")
tell (text items of I) to set end of Stats to {it's rest as text, it's beginning as number}
end repeat
set AppleScript's text item delimiters to tid
Stats
ok, i went through this & i’m willing to admit i’m wrong. this:
set the_list to do shell script "ps -Acr -o %cpu,command | awk '/[0-9]/ {OFS = \"" & "\\" & "r" & "\"; if ($4 != \"\") {print $1, $2 \" \" $3 \" \" $4} else if ($3 != \"\") {print $1, $2 \" \" $3} else {print $1, $2}}'"
set psList to paragraphs of result
somewhat does what’s requested, but only if the process has 3 or less words in it. it’s definitely inferior to the other scripts. i may bang my head against this a bit further, but i’ll have to do it at another time.
Well, I was on a break while traveling, and wasn’t able to test anything. (Yes, I checked this on the road. I’m. dedicated. ;)) I just thought you may not have caught the “separation” part. Plus, I can’t recall having ever used words in a script; I probably wouldn’t have thought of it if I did have the chance.
Um, only if you want me to. Don’t worry, if I had a problem, you would know it (privately).
About Adam’s list; This would work:
tell (text items of I)
set end of Stats to it's beginning as number
set end of Stats to it's rest as text
end tell
These lists of lists are still too complicated for me. I tried to remove all entries which has 0.0 so i added:
set my_result to every item in Stats whose second item is not “0.0” but it dont work?
set Stats to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
repeat with I in paragraphs of (do shell script "ps -Acr -o %cpu,command | sed 1d | sed 's/^ *//'")
tell (text items of I) to set end of Stats to {it's rest as text, it's beginning as number}
end repeat
set AppleScript's text item delimiters to tid
Stats
set Stats to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
repeat with I in paragraphs of (do shell script "ps -Acr -o %cpu,command | sed 1d | sed 's/^ *//'")
tell (text items of I) to if text item 1 is not "0.0" then set end of Stats to {it's rest as text, it's beginning as number}
end repeat
set AppleScript's text item delimiters to tid
Stats
PS: I get a “can’t make … into number” error with “…beginning as number”, “…beginning as real” works