前提・実現したいこと
実現したいこと
objective-cからSafariを起動し、今起動したSafariを特定して、そのウィンドウの数(count)を得たい
前提
- Xcode 11.3.1
- macOS 10.15.3 Catalina
- Safari 13.0.5
発生している問題・エラーメッセージ
発生している問題としては、そのウィンドウの数を取得しようとした時、必ず nil
が返されることです。
(lldb) po [[safariApp windows] count] nil
該当のソースコード
objectivec
1 NSArray<NSRunningApplication*>* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: @"com.apple.Safari"]; 2 NSMutableSet *safariPidSet = [NSMutableSet set]; 3 for (NSRunningApplication* runningApp in apps) 4 { 5 int safariPid = [runningApp processIdentifier]; 6 [safariPidSet addObject: [NSNumber numberWithInt:(int)safariPid]]; 7 } 8 9 // Insert code here to initialize your application 10 NSWorkspace* ws = [NSWorkspace sharedWorkspace]; 11 [ws openURLs:[NSArray arrayWithObject:[NSURL URLWithString:@"https://google.co.jp"]] 12 withAppBundleIdentifier:@"com.apple.Safari" 13 options: NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance 14 additionalEventParamDescriptor:nil 15 launchIdentifiers:nil]; 16 17 int invokedSafariPid = 0; 18 apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: @"com.apple.Safari"]; 19 for (NSRunningApplication* runningApp in apps) 20 { 21 int safariPid = [runningApp processIdentifier]; 22 if (![safariPidSet containsObject: [NSNumber numberWithInt:(int)safariPid]]) 23 { 24 invokedSafariPid = safariPid; 25 break; 26 } 27 } 28 29 SafariApplication *safariApp = [SBApplication applicationWithProcessIdentifier:invokedSafariPid]; 30 [[safariApp windows] count];
試したこと
[safariApp windows]
がダメなのだろうと考え、[safariApp documents]
などに変更してみましたが、結果は同様でした。
また、そもそもこの問題に関する文献が少なく、それ以上何も調査できていない状態です。
あなたの回答
tips
プレビュー