ScriptingBridge Finder POSIX 路径

发布于 2024-09-06 09:49:39 字数 229 浏览 3 评论 0原文

是否可以使用 Scripting Bridge 框架获取最前面窗口的 POSIX 路径或目标?

我正在使用,

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

但我在“Finder.h”中找不到任何可以工作的内容。

is it possible to get the POSIX path or target to the frontmost window using the Scripting Bridge framework?

I'm using

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

but I can't find anything in "Finder.h" that could work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏月而来 2024-09-13 09:49:39

这可能就是您使用 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);

This might be what you are after using ScriptingBridge and 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);
感性 2024-09-13 09:49:39

通过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

Running drawnonward's code through appscript's ASTranslate tool gives me this:

#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];

The result will be an ASAlias instance; use -[ASAlias path] to get the POSIX path.

You can't do it in SB short of resorting to raw Apple event codes as that's one of the features the Apple engineers forgot/didn't bother to put into SB's less than stellar API.

夏日落 2024-09-13 09:49:39

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

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

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

I have not used ScriptingBridge. As part of an NSAppleScript it would be:

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

Hopefully that helps. I think the POSIX part is from the StandardAdditions ScriptingAddition, not the Finder itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文