What replaces the now-deprecated Carbon.File.FSResolveAliasFile in Python on OSX?

后端 未结 3 1728
夕颜
夕颜 2020-12-21 18:33

In Python 2, I can use the following code to resolve either a MacOS alias or a symbolic link:

from Carbon import File
File.FSResolveAliasFile(alias_fp, True)         


        
3条回答
  •  鱼传尺愫
    2020-12-21 19:00

    The following Cocoa code will resolve alias.

    NSURL *targetOfAlias(NSURL *url) {
        CFErrorRef *errorRef = NULL;
        CFDataRef bookmark = CFURLCreateBookmarkDataFromFile (NULL, (__bridge CFURLRef)url, errorRef);
        if (bookmark == nil) return nil;
        CFURLRef resolvedUrl = CFURLCreateByResolvingBookmarkData (NULL, bookmark, kCFBookmarkResolutionWithoutUIMask, NULL, NULL, false, errorRef);
        CFRelease(bookmark);
        return CFBridgingRelease(resolvedUrl);
    }
    

    I don't know how to invoke Cocoa framework from Python, but I am sure someone has done it

    The following link shows code to resolve aslias or symlink https://stackoverflow.com/a/21151368/838253

提交回复
热议问题