2011-04-02 148 views
2

我正在使用NSAppleScript从我的应用程序中运行applescript。我的问题是我有一个NSURL,我想转换为字符串。当我转换它时,我得到:path/to/my/file,但是applescript需要path:to:my:file。我怎样才能将我的NSURL转换成这种格式?谢谢。将NSURL转换为AppleScript文件路径

回答

3

,而不是

file "foo:bar:baz" 

使用

POSIX file "foo/bar/baz" 
+0

非常感谢你许多。 – user635064 2011-04-02 02:09:11

+0

哇!它拯救了我的一天 - 我正在寻找它 - 谢谢你 – 2014-01-29 06:25:55

4

你可能会发现这很有用它将pathString转换为HFS风格的路径(用冒号):

NSString* pathString = [@"~/Desktop/Home.m4v" stringByExpandingTildeInPath]; 
NSURL* theFileURL = [NSURL fileURLWithPath:pathString]; 

NSString* path = [(NSString*)CFURLCopyFileSystemPath((CFURLRef)theFileURL, kCFURLHFSPathStyle) autorelease]; 

NSLog(@"path= %@",path);