是否可以使用Scripting Bridge框架将POSIX路径或目标移动到最前面的窗口?ScriptingBridge Finder POSIX路径
我使用
FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";
,但我无法找到“Finder.h”任何可能的工作。
是否可以使用Scripting Bridge框架将POSIX路径或目标移动到最前面的窗口?ScriptingBridge Finder 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);
我还没有使用ScriptingBridge。作为NSAppleScript的一部分,它将是:
get POSIX path of (target of window 1 as alias)
希望有帮助。我认为POSIX部分来自StandardAdditions ScriptingAddition,而不是Finder本身。
通过appscript's ASTranslate工具运行drawnonward的代码给了我这样的:
#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路径]来获取POSIX路径。
你不能在SB中使用原始Apple事件代码,因为这是Apple的工程师忘记/不打算将其放入SB的less than stellar API中的功能之一。
附录:Finder的设计师们不够好,包括'URL'属性,会给你一个文件的URL字符串。稍微摆弄一下,你可能会说服SB检索这个值,此时你可以使用NSURL来转换一个POSIX路径字符串。 – has 2010-06-19 14:46:24
是的,好主意,正是我需要的。谢谢。 – sergiobuj 2010-06-20 00:45:21
很高兴帮助, 记住把它放在try/catch块之类的东西里,否则如果没有窗口打开,你会得到一个'越界'的错误。 – markhunte 2010-06-20 08:49:46