LoginSignup
1
2

More than 5 years have passed since last update.

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

Posted at
  • 反応しなくなったアプリケーションを強制的に閉じるときに使える
  • 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クラスを使って作成
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2