gpt4 book ai didi

objective-c - 使用 Finder + ScriptingBridge 按路径名/URI 处理文件

转载 作者:行者123 更新时间:2023-12-03 17:00:08 28 4
gpt4 key购买 nike

我正在使用 sdef 实用程序生成的 Finder.h header ,并且许多 Finder SB 方法似乎需要 FinderItem 类型的对象来执行任何有意义的操作。

我将如何根据文件的路径或 URI 创建其中一个对象?

我得到的最远的是 SB 指南中简要提到的 [SBObject initWithProperties] 方法,但不知道从哪里开始。我想翻译成 Objective-C 的基本 AppleScript 是这样的,换句话说:

set myFile to POSIX file 
"/untitled folder/funneh/keyboardcat.mov"

最佳答案

如果您只想要 FinderItem 对象,那么如果您更改行,slf 的代码将起作用:

NSURL* theFileURL = [pathString fileURLWithPath:pathString];

NSURL* theFileURL = [NSURL fileURLWithPath:pathString];

但是如果你想要一个 HFS 风格的路径,那么我找到了这个片段。

NSString* path = [(NSString*)CFURLCopyFileSystemPath((CFURLRef)theFileURL, kCFURLHFSPathStyle) autorelease];
NSLog(@"path= %@",path);

返回字符串“Hard Disk:untitledfolder:funneh:keyboardcat.mov”

该片段可以在 here 中找到.

关于objective-c - 使用 Finder + ScriptingBridge 按路径名/URI 处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3228829/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com