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 路径。

你不能在 SB 中使用原始 Apple 事件代码,因为这是 Apple 工程师忘记/懒得将其放入 SB不那么出色的 API的功能之一。

于 2010-06-19T14:36:49.257 回答
0

我没有使用过 ScriptingBridge。作为 NSAppleScript 的一部分,它将是:

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

希望这会有所帮助。我认为 POSIX 部分来自 StandardAdditions ScriptingAddition,而不是 Finder 本身。

于 2010-06-19T06:16:42.203 回答