FROM : James J. Merkel
DATE : Sun Nov 28 21:58:14 2004
I have playing with a method to get the comment from the Finder's Get
Info window as follows:
-(void)checkFinderCommentsForFile:theFile{
/* Need to use Applescript to read or write Finder Get Info Comments */
/* Convert POSIX path string to hfs path string */
NSURL * urlWithPOSIXPath = [NSURL fileURLWithPath:theFile];
NSString * hfsStylePathString = (NSString
*)CFURLCopyFileSystemPath((CFURLRef)urlWithPOSIXPath,
kCFURLHFSPathStyle);
NSString *appleScriptString = @"tell application \"Finder\"\r get
comment of file ";
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString
stringByAppendingString:hfsStylePathString];
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:@"\r end
tell\r"];
NSLog(appleScriptString);
NSString *finderComment;
NSAppleScript *theScript = [[NSAppleScript alloc]
initWithSource:appleScriptString];
NSDictionary *theError = [[NSDictionary alloc] init];
finderComment = [[theScript executeAndReturnError: &theError]
stringValue];
NSLog(@"Finder comment is %@.\n", finderComment);
NSLog([theError description]);
[theScript release];
[theError release];
}
This works fine provided the file in the line:
appleScriptString = [appleScriptString
stringByAppendingString:hfsStylePathString];
is a valid path.
However if I comment out the above line to simulate a null file name, I
get the errors:
NSAppleScriptErrorBriefMessage = "Can't get comment of file \"\".";
NSAppleScriptErrorMessage = "Finder got an error: Can't get comment
of file \"\".";
NSAppleScriptErrorNumber = -1728;
NSAppleScriptErrorRange = <0000001f 00000007 >;
which I would expect, but the application also (sometimes) crashes.
I would have expected that, since an error was detected, a crash would
not occur.
Is this a bug in NSAppleScript. or am I doing something else wrong?
TIA,
Jim Merkel
DATE : Sun Nov 28 21:58:14 2004
I have playing with a method to get the comment from the Finder's Get
Info window as follows:
-(void)checkFinderCommentsForFile:theFile{
/* Need to use Applescript to read or write Finder Get Info Comments */
/* Convert POSIX path string to hfs path string */
NSURL * urlWithPOSIXPath = [NSURL fileURLWithPath:theFile];
NSString * hfsStylePathString = (NSString
*)CFURLCopyFileSystemPath((CFURLRef)urlWithPOSIXPath,
kCFURLHFSPathStyle);
NSString *appleScriptString = @"tell application \"Finder\"\r get
comment of file ";
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString
stringByAppendingString:hfsStylePathString];
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:@"\r end
tell\r"];
NSLog(appleScriptString);
NSString *finderComment;
NSAppleScript *theScript = [[NSAppleScript alloc]
initWithSource:appleScriptString];
NSDictionary *theError = [[NSDictionary alloc] init];
finderComment = [[theScript executeAndReturnError: &theError]
stringValue];
NSLog(@"Finder comment is %@.\n", finderComment);
NSLog([theError description]);
[theScript release];
[theError release];
}
This works fine provided the file in the line:
appleScriptString = [appleScriptString
stringByAppendingString:hfsStylePathString];
is a valid path.
However if I comment out the above line to simulate a null file name, I
get the errors:
NSAppleScriptErrorBriefMessage = "Can't get comment of file \"\".";
NSAppleScriptErrorMessage = "Finder got an error: Can't get comment
of file \"\".";
NSAppleScriptErrorNumber = -1728;
NSAppleScriptErrorRange = <0000001f 00000007 >;
which I would expect, but the application also (sometimes) crashes.
I would have expected that, since an error was detected, a crash would
not occur.
Is this a bug in NSAppleScript. or am I doing something else wrong?
TIA,
Jim Merkel
| Related mails | Author | Date |
|---|---|---|
| James J. Merkel | Nov 28, 21:58 | |
| Charles Srstka | Nov 28, 22:51 | |
| Nick Zitzmann | Nov 28, 23:08 | |
| James J. Merkel | Nov 29, 01:51 | |
| Charles Srstka | Nov 29, 02:22 | |
| James J. Merkel | Nov 29, 03:36 |






Cocoa mail archive

