NSWorkspaceWillLaunchApplicationNotification
アプリケーションが起動しようとするときにポストされる通知
解説
アプリケーションが起動しようとするときにポストされます。
システムはバックグラウンドアプリケーションやInfo.plistにLSUIElementキーを含むアプリではこの通知をポストしません。
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
更新時のバージョン
OS X 10.10.3
Swift1.2
参照
関連記事(外部サイト)
例文
//NSWorkspace NSWorkspaceWillLaunchApplicationNotification //アプリケーションが起動しようとするとき var switch048 : Bool = false func notifyNSWorkspaceWillLaunchApplicationNotification(notify:NSNotification) { //NSLog("%@",notify.description) let bundleID : String = (notify.userInfo! as Dictionary)["NSApplicationBundleIdentifier"]! as! String NSLog("Bundle ID = %@",bundleID) // -> Bundle ID = com.apple.mail let appName : String = (notify.userInfo! as Dictionary)["NSApplicationName"]! as! String NSLog("application name = %@",appName) // -> application name = メール let appPathe : String = (notify.userInfo! as Dictionary)["NSApplicationPath"]! as! String NSLog("application path = %@",appPathe) // -> application path = /Applications/Mail.app let appProcessID : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessIdentifier"]! as! NSNumber NSLog("process id = %d",appProcessID.integerValue) // -> process id = 36580 let appProcessSerialNumberHigh : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberHigh"]! as! NSNumber NSLog("process serial number high = %d",appProcessSerialNumberHigh.integerValue) // ->process serial number high = 0 let appProcessSerialNumberLow : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberLow"]! as! NSNumber NSLog("process serial number low = %d",appProcessSerialNumberLow.integerValue) // ->process serial number low = 5145832 let runningApp : NSRunningApplication = (notify.userInfo! as Dictionary)["NSWorkspaceApplicationKey"]! as! NSRunningApplication NSLog("runningApp = %@",runningApp.description) // ->runningApp = <NSRunningApplication: 0x600000105340 (com.apple.mail - 36867)> NSLog("runningApp = %@",runningApp.launchDate!.description) // ->runningApp = 2015-04-29 09:18:27 +0000 } @IBAction func function048(sender: AnyObject) { let notificationName : String = NSWorkspaceWillLaunchApplicationNotification let notificationSelector : Selector = Selector("notifyNSWorkspaceWillLaunchApplicationNotification:") if switch048 { //通知の監視をやめる NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self, name: notificationName, object: nil ) NSLog("--------observe off") switch048 = false }else{ //通知の監視を始める NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: notificationSelector, name: notificationName, object: nil ) NSLog("--------observe on") switch048 = true } }