1

現在アクティブなアプリのプロパティを取得したいと思います。これは ScriptingBridge で可能であることは理解していますが、これには sdef ファイルを生成し、ターゲットにしようとしているアプリのプロジェクトにインポートする必要があるようです。すべてのアプリを対象にしたいので、これを行う別の方法はありますか?

システム設定へのアクセス例:

    SystemPreferencesApplication *systemPreferences =
[SBApplication
 applicationWithBundleIdentifier:@"com.apple.systempreferences"];

アクティブなアプリのプロパティにアクセスする別の方法がある場合は、共有してください。(例; ウィンドウタイトル)

ありがとう。

4

2 に答える 2

0

AppleScript を実行したいとします。スクリプト ブリッジは、実行する AppleScript コードがたくさんある場合に適しています。ただし、少量しかない場合は、より簡単な方法は NSApplescript を使用することです。

たとえば、このapplescriptを実行したい場合...

tell application "System Events"
    set theProcesses to processes
    repeat with aProcess in theProcesses
        tell aProcess to get properties
    end repeat
end tell

そしたらこんな風に書ける…

NSString* cmd = @"tell application \"System Events\"\nset theProcesses to processes\nrepeat with aProcess in theProcesses\ntell aProcess to get properties\nend repeat\nend tell";
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:cmd];
NSDictionary* errorDict = nil;
NSAppleEventDescriptor* result = [theScript executeAndReturnError:&errorDict];
[theScript release];
if (errorDict) {
    NSLog(@"Error:%@ %@", [errorDict valueForKey:@"NSAppleScriptErrorNumber"], [errorDict valueForKey:@"NSAppleScriptErrorMessage"]);
    return;
}

// do something with result
NSLog(@"result: %@", result);
于 2013-02-17T00:36:24.500 に答える
0

現在実行中のすべてのアプリケーションのリストを取得するには、

NSWorkSpace.sharedWorkspace.runningApplications;

その配列内の各オブジェクトは、自由にクエリおよび操作できるNSRunningApplicationである必要があります。

于 2013-02-16T22:13:26.527 に答える