I am developing a dashboard widget where it has a requirement to read a file from the hard disk. I got to know that accessing the file is not possible in java script. Going through the apple documentation found it is possible using the cocoa plugin. But just with following the example mentioned in the apple documentation i couldn't get this to work. I have just created a new bundle added a .h and .m file and implemented the webkit methods. Now i just at least just want to invoke a cocoa method from the widget js. Does anybody have a sample code illustrating a cocoa bundle with dashboard widget? Just invoking a simple method which returns NSSString would be fine.
Here is the code I have written in my FileAccess bundle.(ReadFile.m)
#import <WebKit/WebKit.h>
@implementation ReadFile
- (void) windowScriptObjectAvailable:(WebScriptObject *) windowScriptObject {
[windowScriptObject setValue:self forKey:@"MyWindowScriptObject"];
}
- (NSString *)fileData {
return @"File contents";
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector {
return NO;
}
+ (BOOL)isKeyExcludedFromWebScript:(const char *)name {
return NO;
}
@end
Thanks.
Missed a method to implement in ReadFile class.