Posted at

Cocoaの機能を使ってアプリケーションを強制終了するAppleScriptハンドラ

More than 3 years have passed since last update.


  • 反応しなくなったアプリケーションを強制的に閉じるときに使える

  • background onlyのアプリケーションも対象にできる

use scripting additions

use framework "AppKit"

my forceQuitApplication("SystemUIServer")

on forceQuitApplication(anApplication)
--require Framework: AppKit
tell application "System Events"
set bundleIdentifier to bundle identifier of my getProcess(anApplication)
end tell
return (current application's NSRunningApplication's runningApplicationsWithBundleIdentifier:bundleIdentifier)'s forceTerminate as boolean
end forceQuitApplication

on getProcess(args)
tell application "System Events"
if class of args = application then
return application process (name of args)
else if class of args = application process then
return args
else
return application process (args as text)
end if
end tell
end getProcess


更新履歴


  • 2016-01-31: AppKitフレームワークのNSRunningApplicationクラスを使って作成