4

Scripting Bridgeフレームワークを使用して、POSIXパスまたはターゲットを最前面のウィンドウに取得することは可能ですか?

使っています

FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";

しかし、「Finder.h」には機能するものが見つかりません。

4

3 に答える 3

4

これは、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);
于 2010-06-19T18:29:41.693 に答える
2

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つであるためです。

于 2010-06-19T14:36:49.257 に答える
0

ScriptingBridge は使用していません。NSAppleScript の一部として、次のようになります。

get POSIX path of (target of window 1 as alias)

うまくいけば、それは役に立ちます。POSIX 部分は、Finder 自体ではなく、StandardAdditions ScriptingAddition によるものだと思います。

于 2010-06-19T06:16:42.203 に答える