applescript,包括做 shell 脚本不工作

applescript, included do shell script not working

我不是开发人员,但尝试使用 applescript 为我做一些工作。 我有一个小脚本可以找到一个应用程序并杀死它。

看了很多文章都没有找到解决方法

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

我得到了进程 ID。

告诉应用程序"System Events" 获取名称 = "Blotter" 的进程 1 --> 申请流程 "Blotter" 获取应用程序进程的 unix id "Blotter" --> 34990 结束告诉

Ergebnis: 34990

但是我杀不死它...

如果能给我小费,我将不胜感激。谢谢

试试这个:

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

通过使用 return 你租用了进程的 unix id,你只是结束了脚本。将 unix id 放在一个变量中,然后在你的 do shell 脚本中使用该变量。