「Xamarin.Mac/スリープからの復帰を検出する」の版間の差分
ナビゲーションに移動
検索に移動
imported>Administrator (→関連項目) |
imported>Administrator |
||
9行目: | 9行目: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | | | + | | [[コンピュータ]]のスリープ突入 || NSWorkspace.WillSleepNotification |
|- | |- | ||
− | | | + | | コンピュータのスリープ復帰 || NSWorkspace.DidWakeNotification |
|- | |- | ||
− | | | + | | [[ディスプレイ]]のスリープ突入 || NSWorkspace.ScreensDidSleepNotification |
|- | |- | ||
| ディスプレイのスリープ復帰 || NSWorkspace.ScreensDidWakeNotification | | ディスプレイのスリープ復帰 || NSWorkspace.ScreensDidWakeNotification |
2016年5月18日 (水) 02:30時点における最新版
概要[編集 | ソースを編集]
Mac OS Xのスリープからの復帰時にスクリプトを実行したい。 Windowsではタスクスケジューラーで出来るが、Mac OS Xには標準で無さそうなので自作するしかなさそうだ。
実装[編集 | ソースを編集]
スリープ状態はNotificationCenterから取得することができる。
「コンピューターのスリープ」と「ディスプレイのスリープ」が別通知なので注意すること。この例では「コンピューターのスリープ」のみ対応しているが、現実的は両方を記述することになると思う。
コンピュータのスリープ突入 | NSWorkspace.WillSleepNotification |
コンピュータのスリープ復帰 | NSWorkspace.DidWakeNotification |
ディスプレイのスリープ突入 | NSWorkspace.ScreensDidSleepNotification |
ディスプレイのスリープ復帰 | NSWorkspace.ScreensDidWakeNotification |
using System;
using AppKit;
using Foundation;
namespace NotificationSleepWake
{
[Register("AppDelegate")]
public class AppDelegate : NSApplicationDelegate
{
public AppDelegate()
{
}
NSObject _wake;
public override void DidFinishLaunching(NSNotification notification)
{
// Insert code here to initialize your application
if (_wake == null)
{
_wake = NSWorkspace.SharedWorkspace.NotificationCenter.AddObserver(
NSWorkspace.DidWakeNotification,
(notify) =>
{
Console.WriteLine("wake");
});
}
}
public override void WillTerminate(NSNotification notification)
{
if (_wake != null)
{
NSWorkspace.SharedWorkspace.NotificationCenter.RemoveObserver(_wake);
}
}
}
}
関連項目[編集 | ソースを編集]
- Mac OS X/日時を強制的にアップデートする
- Xamarin.Mac/システムステータスバーにアイコンを表示する
- Xamarin.Mac/Dockアイコンを非表示にする
- Xamarin.Mac/AppleScriptを実行する
- Xamarin.Mac/管理者権限に昇格して実行する