(コメントに収めるには長すぎるため、これを個別の回答として投稿してください)
元のスクリプトの@MatthieuRieglerへのクレジット。
これは10.12.6で機能し、元のスクリプトを少し変更したものです(私が自分で調査した後に@CharlieGorichanazのコメントを見ました)。
set textToSearchForInProcessName to "Not Responding"
-- Run Activity Monitor
tell application "Activity Monitor" to activate
tell application "System Events" to tell process "Activity Monitor"
-- Wait for the Activity Monitor window to open
repeat until (exists window 1)
delay 1
end repeat
--display notification "Window appeared"
-- Wait for the Menubar to be present
repeat until (exists menu 1 of menu bar item "View" of menu bar 1)
delay 1
end repeat
--display notification "Menubar appeared"
-- Make sure View -> My Processes is selected
click menu item "My Processes" of menu 1 of menu bar item "View" of menu bar 1
-- Click the 'CPU View' button ( **1 )
click radio button 1 of radio group 1 ¬
of group 2 of toolbar 1 ¬
of window 1
-- Working with the list of processes
tell outline 1 of scroll area 1 of window 1
-- Looking for Not responding process
set notResponding to rows whose value of ¬
first static text contains textToSearchForInProcessName
repeat with aProcess in notResponding
-- For each non responding process retrieve the PID
set pid to value of text field 1 of aProcess -- ( **2 )
-- Kill that process using pid
if pid is not "" then do shell script ("kill -9 " & pid)
end repeat
end tell
end tell
** 1
macOS 10.12.xでは、
ボタンのセット(CPU、メモリ、エネルギーなど)のgroup 2 of toolbar 1
代わりにツールバーに追加のアイコンが含まれています group 1 of toolbar 1
。そのアイコンがない場合(私は古いmacOSバージョンでは確認していません)、CPUなどのボタンがgroup 1 of toolbar 1

** 2
これは、アクティビティ列のPID列を別の位置にドラッグしたことがある場合に適用されます。PID列を左端の位置にドラッグしたので、この行で、インデックスを1
次のように変更する必要がありました。
set pid to value of text field 1 of aProcess
列には、1から始まる左端から番号が付けられています。したがって、必要に応じて、上記の行で強調表示されているインデックスを適宜調整してください。