I used codes below to open a file
NSOpenPanel * panel = [NSOpenPanel openPanel];
[panel setCanSelectHiddenExtension:YES];
[panel setRequiredFileType:@"scpt"];
[panel setAllowsOtherFileTypes:NO];
[panel
beginSheetForDirectory:nil
file:@"Script"
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector (openFileDidEnd:returnCode:contextInfo:)
contextInfo:nil];
-(void)openFileDidEnd:(NSSavePanel*)panel returnCode:(int)returnCode contextInfo:(void*)contextInfo
{
if(returnCode == NSOKButton)
{
NSString *s=[[panel URL] absoluteString];
[NSThread detachNewThreadSelector:@selector(setFileString:) toTarget:self withObject:s ];
}
};
s value is 'file://home/Users/myName/Desktop/1.scpt'
if I call
bool b=[[NSFileManager defaultManager] fileExistsAtPath:@"file://home/Users/myName/Desktop/1.scpt"];
check if the file with path s exists, it always returns 0
but if I checked in Finder, I found its path is '/Users/myName/Desktop/1.scpt'
bool b=[[NSFileManager defaultManager] fileExistsAtPath:@"/Users/myName/Desktop/1.scpt"];
will return YES!
How can I get the correct string path from url of NSOpenPanel ?
Welcome any comment