1
votes

I'm not a developer but try to use applescript to do some work for me. I have a small script to find a application and kill it.

I have read many articles but not found a solution.

tell application "System Events"

    set x to first process whose name is "Blotter"
    return unix id of x

end tell

try
    do shell script "kill " & x
end try

I get the process id as a result.

tell application "System Events" get process 1 whose name = "Blotter" --> application process "Blotter" get unix id of application process "Blotter" --> 34990 end tell

Ergebnis: 34990

But I'm not able to kill it...

I would be really grateful for a tipp. Thanks

1
Why AppleScript? Just use Terminal: killall Blotter - user3439894
Thanks for your answer. I use AppleScript because I want to run the job one a day. And this is just the start of the job to do... - gr8
Try sending a stronger signal than SIGTERM (the default), with do shell script "kill -9 " & x. or equally using the name instead of number... kill -s KILL PID - Mark Setchell
does not work either, somehow i guess the kill comand is not executed... i can kill it in another applescript: try do shell script "kill 34945" end try - gr8
The return statement does just that - it returns from the script, which ends it. - red_menace

1 Answers

0
votes

Try this instead:

tell application "System Events"
    set proc to first process whose name is "Blotter"
    set procID to unix id of proc
end tell

try
    do shell script "kill " & procID
on error errstr
    display alert errstr
end try

by using return you' rent getting the unix id of the process, you're merely ending the script. Put the unix id in a variable, and then use that variable in your do shell script.