「Xamarin.Mac/システム環境設定を開く」の版間の差分
| (同じ利用者による、間の2版が非表示) | |||
| 41行目: | 41行目: | ||
Console.WriteLine(id); | Console.WriteLine(id); | ||
} | } | ||
</source> | |||
動的なメソッド呼び出しはPerformSelectorメソッドで行える。Xamarin公式のScripting Bridgeで[[Finder]]を制御しているサンプルを参考に実装したのでこれで正しいのかは知らん。<ref>https://github.com/mono/monomac/blob/master/samples/attic/ScriptingBridgeFinder/MainWindowController.cs</ref>。 | |||
<source lang="csharp"> | |||
static void Main(string[] args) | |||
{ | |||
NSApplication.Init(); | |||
//NSApplication.Main(args); | |||
// システム環境設定 | |||
var systemPrefs = SBApplication.FromBundleIdentifier(@"com.apple.systempreferences"); | |||
//systemPrefs.Activate(); | |||
var panes = systemPrefs.ValueForKey(new NSString("panes")) as SBElementArray; | |||
for (int i = 0; i < panes.Count; i++) | |||
{ | |||
var pane = panes.GetItem<NSObject>(i); | |||
var id = pane.ValueForKey(new NSString("id")) as NSString; | |||
Console.WriteLine(id); | |||
// セキュリティとプライバシー | |||
if (id == "com.apple.preference.security") | |||
{ | |||
var anchors = pane.ValueForKey(new NSString("anchors")) as SBElementArray; | |||
for (int j = 0; j < anchors.Count; j++) | |||
{ | |||
var anchor = anchors.GetItem<NSObject>(j); | |||
var name = anchor.ValueForKey(new NSString("name")) as NSString; | |||
Console.WriteLine(name); | |||
// アクセシビリティ | |||
if (name == "Privacy_Accessibility") | |||
{ | |||
anchor.PerformSelector(new Selector("reveal")); | |||
// 表示 | |||
systemPrefs.Activate(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
</source> | </source> | ||
| 54行目: | 96行目: | ||
==関連項目== | ==関連項目== | ||
*[[Xamarin.Mac/Global Event Monitorでキー入力を監視する]] | |||
==参考文献== | ==参考文献== | ||