Scripting Bridgeフレームワークを使用して、POSIXパスまたはターゲットを最前面のウィンドウに取得することは可能ですか?
使っています
FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";
しかし、「Finder.h」には機能するものが見つかりません。
Scripting Bridgeフレームワークを使用して、POSIXパスまたはターゲットを最前面のウィンドウに取得することは可能ですか?
使っています
FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";
しかし、「Finder.h」には機能するものが見つかりません。
これは、ScriptingBridge と NSURL を使用した後の状態である可能性があります。
FinderApplication *finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
SBElementArray *windows = [finder windows ]; // array of finder windows
NSArray *targetArray = [windows arrayByApplyingSelector:@selector(target)];// array of targets of the windows
//gets the first object from the targetArray,gets its URL, and converts it to a posix path
NSString * newURLString = [[NSURL URLWithString: (id) [[targetArray objectAtIndex:0]URL]] path];
NSLog(@"newURLString %@ ", newURLString);
appscript のASTranslate ツールを使用して drawonwardのコードを実行すると、次のようになります。
#import "FNGlue/FNGlue.h"
FNApplication *finder = [FNApplication applicationWithName: @"Finder"];
FNReference *ref = [[[finder windows] at: 1] target];
FNGetCommand *cmd = [[ref get] requestedType: [ASConstant alias]];
id result = [cmd send];
結果は ASAlias インスタンスになります。-[ASAlias path] を使用して POSIX パスを取得します。
生のAppleイベントコードに頼る以外にSBでそれを行うことはできません。これは、AppleのエンジニアがSBのあまり優れていないAPIに入れるのを忘れた/気にしなかった機能の1つであるためです。
ScriptingBridge は使用していません。NSAppleScript の一部として、次のようになります。
get POSIX path of (target of window 1 as alias)
うまくいけば、それは役に立ちます。POSIX 部分は、Finder 自体ではなく、StandardAdditions ScriptingAddition によるものだと思います。