1

我正在使用从 sdef 实用程序生成的 Finder.h 标头,并且看起来很多 Finder SB 方法需要 FinderItem 类型的对象来做任何有意义的事情。

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

我得到的最远的是 SB 指南中简要提到的 [SBObject initWithProperties] 方法,但不知道从那里去哪里。那么,我想翻译成 Objective-C 的基本 AppleScript 就是,换一种说法:

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

3 回答 3

2

如果您只想要该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:untitled folder:funneh:keyboardcat.mov”

可以在此处找到该片段。

于 2010-07-12T17:36:14.783 回答
1

我不确定SBObject,但如果你想要一个FinderItem*,这就是你如何得到一个。

NSString* pathString = [@"/untitled folder/funneh/keyboardcat.mov" stringByExpandingTildeInPath];
NSURL* theFileURL = [pathString fileURLWithPath:pathString];
FinderApplication* finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
FinderItem * theItem = [[finder items] objectAtLocation: theFileURL];
于 2010-07-12T13:23:04.860 回答
0

在阅读了一个非常详细的AppleScript 相关答案后,我决定坚持使用appscript,这让事情变得更容易:

FNApplication *finder = [[FNApplication alloc] initWithName:@"Finder.app"];
FNReference *ref = [[finder files] byName: @"/users/movies/kitteh.mov"];
于 2010-07-18T18:44:44.487 回答