How do I get AppleScript to build a list from a data file, csv or similar.
Once the list is built I then want to copy PostScript files according to that list into various folders, then combine them into PDF. :shock:
Maybe something like this will work:
set foo to read file "path:to:file" using delimiter {","} as list
– Rob
I have another question on forming a list. I have been working on a script that will get a list of all the running applications and then allow the user to choose one or more and “kill” them. I use a very simple shell script to return the list of applications and PID’s to applescript.
[PowerBook867:~] tugboat% cat multikill
#!/bin/sh
script to parse out pid’s and application names
ps -awwx | grep -v grep | grep psn_ | awk '{
pid_num = $1
gsub (/^.//,“”,$0)
gsub (/-psn.$/,“”,$0)
print pid_num," " $0
}’
Anyway, the applescript starts out with :
set shell_sc to “~/multikill”
set app_list to do shell script shell_sc
This give me the data I want with the format:
PID Application
2345 iTunes
xxxx another_app
and etc.
What I would like to do is put this in the form of a list, and use the “choose from list” feature to select one or more items and then kill them. I cannot figure out how to turn the data into a list. I am sure this is so simple, I just can’t get it.
Thanks for looking
Andy
Is a PID always 4 digits long?
No, They are one or more digits. I was just using that as an example. Any user launched program would have a pid of 3 digits or more. Perhaps testuser (StaticInnerClass) would remind us of pid numbering convention.
If I understand what you want to do, this should be close. The variable ‘tids_’ will contain a list of the PID numbers that have been selected for killing.
set shellResult to "PID Application
2345 iTunes
4567 iMovie"
set pidList to paragraphs of shellResult as list
set chosen_ to choose from list pidList with multiple selections allowed
set tids_ to {}
set oldDelims to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {" "}
repeat with item_ in chosen_
try
copy (text item 1 of item_ as number) to end of tids_
end try
end repeat
set AppleScript's text item delimiters to oldDelims
on error
set AppleScript's text item delimiters to oldDelims
end try
tids_
– Rob
Rob,
You are fast and awesome. It works perfectly for me. I just could not figure out the list issues.
Andy H