I had this problem, so I applied the command line tool. It is open source located at https://github.com/rptb1/aliasPath
The main thing is that it will work even if this alias is broken, unlike any AppleScript solution I found. Therefore, you can use it to write scripts to fix aliases when many files change volume. That is why I wrote it.
The source code is very short, but here is a summary of the key part for everyone who needs to solve this problem in the code, or who wants to look for the appropriate protocols.
NSString *aliasPath = [NSString stringWithUTF8String:posixPathToAlias]; NSURL *aliasURL = [NSURL fileURLWithPath:aliasPath]; NSError *error; NSData *bookmarkData = [NSURL bookmarkDataWithContentsOfURL:aliasURL error:&error]; NSDictionary *values = [NSURL resourceValuesForKeys:@[NSURLPathKey] fromBookmarkData:bookmarkData]; NSString *path = [values objectForKey:NSURLPathKey]; const char *s = [path UTF8String];
rptb1
source share