Re: NSWorkspace openFile: bug?
Re: NSWorkspace openFile: bug?
- Subject: Re: NSWorkspace openFile: bug?
- From: Brian Ganninger <email@hidden>
- Date: Fri, 5 Jan 2007 13:31:26 -0600
What are you trying to accomplish with the pref pane that can't be
accomplished with basic AppleScript [satisfactorily]? I've had Growl
support for a long while in my apps and to open the pane I've used
the simple AS below with not a complaint as to speed to or problems.
AppleScript:
tell application "System Preferences"
activate
set current pane to pane "com.growl.prefpanel"
end tell
And I've used the following to conditionally enable the Growl-
launching button (a method on my app delegate that I can just bind to):
/* this method looks for common install locations for Growl and let's
us know whether to prompt or not */
-(BOOL)detectGrowl
{
BOOL foundGrowl = NO;
// framework check
if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/
Frameworks/Growl.framework"])
foundGrowl = YES;
if([[NSFileManager defaultManager] fileExistsAtPath:[[NSString
stringWithString:@"~/Library/Frameworks/Growl.framework"]
stringByExpandingTildeInPath]])
foundGrowl = YES;
// preference pane check
if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/
PreferencePanes/Growl.prefPane"])
foundGrowl = YES;
if([[NSFileManager defaultManager] fileExistsAtPath:[[NSString
stringWithString:@"~/Library/PreferencePanes/Growl.prefPane"]
stringByExpandingTildeInPath]])
foundGrowl = YES;
return foundGrowl;
}
On Jan 5, 2007, at 1:09 PM, Paul Borokhov wrote:
Hmmm, I didn't think this all the way through... :( I keep assuming
that it will always succeed on the first iteration, don't know why...
BUT, I'm still looking for a cleaner way of doing this. Is there
such a way? I tried using launchAppWithBundleIdentifier
(specifically, with [[NSWorkspace sharedWorkspace]
launchAppWithBundleIdentifier:@"com.growl.prefpanel"
options:NSWorkspaceLaunchWithoutAddingToRecents
additionalEventParamDescriptor:nil launchIdentifier:nil]), but that
simply returned NO every time. Seems wasteful to do it like this.
And running AppleScripts is something I'd rather avoid, mostly due
to performance issues.
Thanks...
Paul
----------Original Message----------
On 1/5/07 11:03 , John Stiles (email@hidden) wrote:
Is it possible that it is failing in one iteration of your
loop—generating the error—and then succeeding in another
iteration—generating "Found Growl"?
If that isn't the case, and there's a genuine bug, then I'd recommend
using Launch Services directly.
On Jan 5, 2007, at 10:51 AM, Paul Borokhov wrote:
Hello,
It seems that I've run into a bit of an openFile: bug. Using this
code:
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSAllDomainsMask, YES);
int i = 0;
for (i; i<[paths count]; i++) { // 4 domains possible...there needs
to be a better way of doing this
if ([[NSWorkspace sharedWorkspace] openFile:[[paths
objectAtIndex:i]
stringByAppendingPathComponent:@"PreferencePanes/
Growl.prefPane"]]) {
NSLog(@"Found Growl");
i++;
break;
}
}
I still get "Found Growl" printed in the Console EVEN WHEN the open
operation fails. For example, if the pref pane is not to be found in
the user's home, the following gets printed in the Console:
2007-01-05 10:41:31.616 : LSOpenFromURLSpec() returned -43 for
application (null) path
/Users/paulb/Library/PreferencePanes/Growl.prefPane.
2007-01-05 10:41:31.770 : Found Growl
This is obviously wrong, since the docs state that this method is
supposed to return YES if the file was successfully opened;
otherwise, NO. Am I missing something here, or is this really not
working as documented?
Paul
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden