Re: Problem with 'launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:'???
Re: Problem with 'launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:'???
- Subject: Re: Problem with 'launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:'???
- From: Laurent Daudelin <email@hidden>
- Date: Mon, 27 Apr 2009 13:22:46 -0700
Ken,
That did work but I found that I had to keep providing the descriptor
for some reason. Are you using a different API fro the Launch Services?
My only other problem now is switching the default printer to a
specific one and switching back to the original default. lpoptions
seemed promising but it doesn't change it, even though on the command
line, it says it did...
Cheers, Ken!
-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin http://nemesys.dyndns.org
Logiciels Nemesys Software email@hidden
Photo Gallery Store: http://laurentdaudelin.shutterbugstorefront.com/g/galleries
On Apr 23, 2009, at 18:11 , Ken Thomases wrote:
On Apr 23, 2009, at 7:50 PM, Laurent Daudelin wrote:
I'm trying to use this NSWorkspace method to launch an application
and print a document. I provide it with a FSRef-based
NSAppleEventDescriptor but the only thing the workspace does is
launching the app. Here is part of the code:
NSURL *documentURL = [[[NSURL alloc] initFileURLWithPath:
[[openPanel filenames] objectAtIndex:c]] autorelease];
NSURL *applicationURL = NULL;
OSStatus resultCode = LSGetApplicationForURL((CFURLRef)documentURL,
kLSRolesAll, NULL, (CFURLRef *)&applicationURL);
if (resultCode != noErr)
{
NSRunAlertPanel(NULL, [NSString stringWithFormat:@"%@ '%@'",
NSLocalizedString(@"CouldntFindAppForDocument", @""), [[[openPanel
filenames] objectAtIndex:c] lastPathComponent]], NULL, NULL, NULL);
return ;
}
NSBundle *appBundle = [NSBundle bundleWithPath:[applicationURL
path]];
BOOL couldLaunchApp = NO;
NSAppleEventDescriptor *descriptor = [self descriptorWithPath:
[[openPanel filenames] objectAtIndex:c]];
if (descriptor != NULL)
couldLaunchApp = [[NSWorkspace sharedWorkspace]
launchAppWithBundleIdentifier:[appBundle bundleIdentifier]
options:NSWorkspaceLaunchAndPrint
additionalEventParamDescriptor:descriptor launchIdentifier:NULL];
if ( ! couldLaunchApp)
NSRunAlertPanel(NULL, [NSString stringWithFormat:@"%@ '%@'",
NSLocalizedString(@"CouldntAddDocumentToReader", @""), [[[openPanel
filenames] objectAtIndex:c] lastPathComponent]], NULL, NULL, NULL);
What am I doing wrong?
I don't recommend using a -launchApp... method to act on a document.
To print a document, I recommend using -
openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers
: passing NSWorkspaceLaunchAndPrint in the options. Also, pass nil
for the application bundle identifier, since you just want to use
the default. That avoids the overly complicated use of
LSGetApplicationForURL -> URL -> path -> NSBundle -> bundle ID.
Also, the above code snippet snippet seems to be in a loop over the
array of filenames returned by an open panel. With this method, you
can convert that to an array of URLs and make just one NSWorkspace
method call to print them all in their appropriate applications.
Don't bother passing an additionalEventParamDescriptor. It's hard
to get right, and I've seen evidence that it isn't even passed
properly. (I've dropped down to direct use of Launch Services,
which did pass the parameter correctly.)
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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