Hello.
Here is something I used to use, but from a terminal window, it willl ask you about the processes that match your pattern, until you you have answered for each and every one.
Maybe you can rework this functionality into AS. I have been working now and then on a c version, that lists all processes, and lets you kill the one that matches a pattern interactively. I haven’t make it use reg-exe’s yet, so it gives too much back to be useful.
Here is yesno, that queries you for y or n:
[code]#! /bin/bash
### CMD Returns exitcode upon pressing y or n or q, “keypress” read code. !#
Traps ^C to keep our terminal sane under all conditions. Q - quits.
Conventions:
Under no circumstanses will the user have the possibiltiy to interrupt us by pressing ^C
Pressing ^Z on the other hand, is really a feature should the user want to inspect something
before he answer.
Then it is nice to see the previous question again after she presumably have
inspected what she was to do with the item in question.
This is the convention. Its easy to add features like All, by adding some functionality.
trap ‘’ SIGTSTP
trap - SIGTSTP
prgname=yesno
version=“1.0”
Usage=“Usage : $prgname [-huv; --help, --usage, --version ]”
version()
{
echo $prgname" : “$version”
Copyright 2008 (c) Tommy Bollman
Is put in the public domain under the GNU Gpl 2.0 license.
No warranties about what so ever are given about what so ever
- to the extent permitted by law.
$prgname Needs the Bash commandline interpreter in order to work."
tommybollman@mac.com
}
phelp()
{
echo "
$Usage
$prgname : filters the keyboard for the keypresses: [yY] [nN] [qQ] and returns a corresponding
exitcode
lets Suspend interrupts (^Z) fall through and gives an unique returncode when awakes again.
Read the manpage (yesno.1) or read the program code ($0) for information.
INTENT
$prgname : Enables swift responses from the user to the utility, and gives the caller an
opportunity to rerun any questions if the calling process was suspended. Like if the user has
suspended the program to find out if it is really sound to overwrite that file after all.
" 1>&2
}
myhandler()
{
trap ‘’ SIGCONT
echo “interrupted!!!”
exit 101
}
if [ $# -gt 0 ] ; then
if [ $# = 1 ] ; then
if [ “$1” = “-u” -o “$1” = “-h” -o “$1” = “–help” -o “$1” = “–usage” ] ; then
phelp ; exit
elif [ “$1” = “-v” -o “$1” = “–version” ] ; then
version ; exit
else
echo "Bad option $1 " 1>&2
echo $Usage 1>&2
exit
fi
else
echo "Bad nr of arguments " 1>&2
echo $Usage 1>&2
exit
fi
fi
trap ‘’ SIGINT
trap myhandler SIGCONT
while true; do {
ehco here
read -n 1 -s MYCHAR </dev/tty
case "$MYCHAR" in
([yY])
exit 0 ;;
([nN])
exit 1 ;;
([qQ])
exit 99 ;;
esac
} done[/code]
Here is pick, that returns the answers from a query.
[code]#! /bin/bash
### pick: select arguments
declare ret
for i # for each argument
do
echo -n " “$(echo $i |sed -n ‘s/[ ]*$//p’)”:(y/n/q)?" >/dev/tty
yesno
if ret=$? ; [ $ret -eq 0 ] ; then
echo “$i”
echo " – Yes" >/dev/tty
elif [ $ret -eq 99 ] ; then
echo " – Quit" >/dev/tty
exit 1
else
echo " – No" >/dev/tty
fi
done </dev/tty[/code]
here is zap, that kills processes interactively.
[code]#!/bin/bash
zap pat: kill all processes matching pat
final version
exercise version: shows the heading of the ps command as it is.
PATH=/bin:/usr/bin:~/bin
IFS=’
’ # just a newline
case $1 in
“”) echo ‘Usage: zap [-0…15] pattern’ 1>&2; exit 1 ;;
-) SIG=$1; shift
esac
program_arguments_missing=$
processes=${program_arguments_missing:?Usage: zap [-0…15] process name 1 process name 2 …}
processes=$( echo $processes PID )
wantedprocesses=echo $processes |sed 's/ /|/g'
#must really make a temp file here, to keep the process info.
TMPFILE1=/tmp/zap$$
TMPFILE2=/tmp/zap2$$
ps -ax |egrep $wantedprocesses |sed ‘/zap/ d’ >|$TMPFILE1
head -1 <$TMPFILE1 >/dev/tty
sed -e 1d -e ‘/egrep.*PID/ d’ <$TMPFILE1 >|$TMPFILE2
kill $SIG pick \
cat $TMPFILE2 ` | awk ‘{print $1}’` 2>/dev/null[/code]
Both zap and pick are from the book: The Unix Programming Environment.
Edit
Most of the time, I kill processes with Activity monitor, but when I’m in doubt about the command line arguments, and there are multiple processess with a tool involved, then I have to resort to the commandline. Most of the time, Activity Monitor does a good job, as I can search for the process-name in the search field, and there are numerous ways to sort the view too, so I can look for processes by name, or cpu-usage for instance.
Edit+
I played a little with the now obsolete zap script, and I changed it to not include zap itself.
All those three scripts are surmised to reside in a ~/bin folder.