NSWorkspaceScreensDidSleepNotification
画面スリープした後の通知
解説
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.6-
更新時のバージョン
OS X 10.10.3
Swift1.2
参照
関連記事(外部サイト)
例文
//NSWorkspace NSWorkspaceScreensDidSleepNotification //NSWorkspace NSWorkspaceScreensDidWakeNotification //NSWorkspace NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification let theLabel056 : NSTextField = NSTextField(frame: NSMakeRect(10.0, 100.0, 280.0, 30.0)) var switch056 : Bool = false func notify056(notify:NSNotification) { NSLog("!! %@",notify.description) if notify.name == NSWorkspaceScreensDidSleepNotification { theLabel056.stringValue = theLabel056.stringValue + "\n画面スリープしようとした" } if notify.name == NSWorkspaceScreensDidWakeNotification { theLabel056.stringValue = theLabel056.stringValue + "\n画面スリープから目覚めた" } // if notify.name == NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification { theLabel056.stringValue = theLabel056.stringValue + "\nアクティビティ変更" } } @IBAction func function056(sender: AnyObject) { var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false , screen: NSScreen.mainScreen()) windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 theLabel056.stringValue = "通知欄" theLabel056.bordered = false theLabel056.canBecomeKeyView aWindow.contentView.addSubview(theLabel056) aWindow.contentView.addSubview(theView) aWindow.center()//ウインドウをスクリーンの中心に aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 let notificationName1 : String = NSWorkspaceScreensDidSleepNotification let notificationName2 : String = NSWorkspaceScreensDidWakeNotification let notificationName3 : String = NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification let notificationSelector : Selector = Selector("notify056:") if switch056 { //通知の監視をやめる NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self, name: notificationName1, object: nil ) NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self, name: notificationName2, object: nil ) NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self, name: notificationName3, object: nil ) NSLog("--------observe off") switch056 = false }else{ //通知の監視を始める NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, forKeyPath: notificationName1, options:NSKeyValueObservingOptions.New, context: nil) NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: notificationSelector, name: notificationName1, object: nil ) NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: notificationSelector, name: notificationName2, object: nil ) NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: notificationSelector, name: notificationName3, object: nil ) NSLog("--------observe on") switch056 = true } }