[MacRuby-devel] Appscript and pathname translation

Alan Skipp al_skipp at fastmail.fm
Wed Apr 18 07:02:45 PDT 2012


Hi Bob,
If at all possible I'd try and avoid the conversion. If this is not feasible, this could help:

def posix_from_hfs(hfs)
    url = CFURLCreateWithFileSystemPath(nil, hfs, KCFURLHFSPathStyle, false) # final argument is whether the path is a directory or not
    url.path
end

def hfs_from_posix(posix)
    url = NSURL.fileURLWithPath posix
    CFURLCopyFileSystemPath(url, KCFURLHFSPathStyle)
end

The first method needs reworking, as it assumes that the HFS path is not a directory.
I've only did a very brief test of the above code, but it seems to do the job.

Al

On 18 Apr 2012, at 12:48, Robert Schaaf wrote:

> Hello again, Macruby community!
> 
> I'm trying to rewrite a program that drives Excel with appscript, and running into the problem of translating back and forth between HFS and POSIX pathnames.  The old Appscript module included a MacTypes module, and these two translations were provided.
> 
> 1. to go from POSIX to HFS:  
> 
> 	hfs_pathname  = MacTypes::FileURL.path(posix_pathname).hfs_path
> 
> 2. to make the round trip back to POSIX:  
> 	
> 	posix_pathname  = DefaultCodecs.unpack(DefaultCodecs.pack(hfs_pathname).coerce(KAE::TypeFileURL)).path
> 
> Do I need to go to the scripting bridge for this?  This is Core Foundation stuff, and I'm totally at sea.  
> 
> Any help would be greatly appreciated.
> 
> Bob Schaaf
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20120418/b467ed7d/attachment.html>


More information about the MacRuby-devel mailing list