【问题标题】:applescript, included do shell script not workingapplescript,包括做外壳脚本不工作
【发布时间】:2020-02-28 22:02:13
【问题描述】:

我不是开发人员,但尝试使用 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。

告诉应用程序“系统事件” 获取名称=“Blotter”的进程1 --> 应用程序“Blotter” 获取应用程序进程“Blotter”的unix id --> 34990 结束告诉

厄格布尼斯: 34990

但我无法杀死它......

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

【问题讨论】:

  • 为什么选择 AppleScript?只需使用终端:killall Blotter
  • 感谢您的回答。我使用 AppleScript 是因为我想每天运行一项工作。而这只是工作的开始......
  • 尝试使用do shell script "kill -9 " & x 发送比SIGTERM(默认)更强的信号。或者同样使用名称而不是数字...kill -s KILL PID
  • 也不起作用,不知何故我猜kill命令没有执行......我可以在另一个applescript中杀死它:try do shell script "kill 34945" end try
  • return 语句就是这样做的——它从脚本返回,脚本结束。

标签: applescript


【解决方案1】:

试试这个:

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 脚本中使用该变量。

【讨论】:

  • 这行得通,非常感谢您....现在我将尝试将其余部分放在一起....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多