Re: Set default browser and mailapp
Re: Set default browser and mailapp
- Subject: Re: Set default browser and mailapp
- From: Christian Weykopf <email@hidden>
- Date: Fri, 25 Oct 2002 02:05:36 +0200
Am Donnerstag den, 24. Oktober 2002, um 17:25, schrieb Quinn:
At 18:04 +0200 23/10/02, Christian Weykopf wrote:
are there any errors in my code? I've tried it on severel machines.
In my app I write a lot more keys. All are stored except the mailapp and
browser. This happens with Jaguar and 10.1.5.
The code looks OK, except that you've commented out the following.
/* strcpy (&icAppSpec.name[1], "Internet Explorer");
icAppSpec.name[0] = strlen ("Internet Explorer");*/
I assume that you tried it out both ways and neither worked?
* * *
I actually wrote some code to test this. The code is included below. I
switch the mailto helper, rather than the HTTP helper, because that's more
convenient for me. I originally had problems getting this to work, but I
eventually figured out the problem. Mac OS X is much more picky about the
value you supply for spec.name than traditional Mac OS. On older systems,
the spec.name value was just a comment, but Mac OS X passes it to Launch
Services to help find the application. If you don't get the value right,
the call fails silently. In my case, I had to change "Mail" to "Mail.app"
to get things to work.
Ah, shame on me. I've tried the display name and the full path, but not the
app name.
It works, great. thanks
The LS call used is LSFindApplicationForInfo, so I use that to preflight
the call.
I think there's room for improvement in our implementation of ICSetPref,
so I filed this as a bug [Radar ID 3083201].
S+E
Quinn
----------------------------------------------------------------------------
/*
File: ICTest.c
Contains: A program to toggle the mail helper between Mail and
Eudora.
Written by: DTS
Copyright: Copyright ) 2000-2001 by Apple Computer, Inc., All Rights
Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by
Apple Computer, Inc.
("Apple") in consideration of your agreement to the
following terms, and your
use, installation, modification or redistribution of this
Apple software
constitutes acceptance of these terms. If you do not
agree with these terms,
please do not use, install, modify or redistribute this
Apple software.
In consideration of your agreement to abide by the
following terms, and subject
to these terms, Apple grants you a personal, non-exclusive
license, under Apple's
copyrights in this original Apple software (the "Apple
Software"), to use,
reproduce, modify and redistribute the Apple Software,
with or without
modifications, in source and/or binary forms; provided
that if you redistribute
the Apple Software in its entirety and without
modifications, you must retain
this notice and the following text and disclaimers in all
such redistributions of
the Apple Software. Neither the name, trademarks, service
marks or logos of
Apple Computer, Inc. may be used to endorse or promote
products derived from the
Apple Software without specific prior written permission
from Apple. Except as
expressly stated in this notice, no other rights or
licenses, express or implied,
are granted by Apple herein, including but not limited to
any patent rights that
may be infringed by your derivative works or by other
works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS"
basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT
LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND
FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL,
INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER
THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,
EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Change History (most recent first):
*/
#if defined(__MACH__)
#include <Carbon/Carbon.h>
#else
#include <MacTypes.h>
#include <InternetConfig.h>
#include <PLStringFuncs.h>
#include <LaunchServices.h>
#include <CFStringEncodingExt.h>
#endif
#include <stdio.h>
#include <assert.h>
void main(void)
{
OSStatus err;
OSStatus junk;
ICInstance inst;
fprintf(stderr, "Hello Cruel World!\n");
fprintf(stderr, "Standard.c\n");
err = ICStart(&inst, '????');
if (err == noErr) {
ICAppSpec spec;
ICAppSpec newSpec;
ICAttr junkAttr;
long size;
size = sizeof(spec);
err = ICGetPref(inst, "\pHelper*mailto", &junkAttr, &spec, &size)
;
if (err == noErr) {
if (spec.fCreator == 'CSOm') {
spec.fCreator = 'emal';
PLstrcpy(spec.name, "\pMail.app");
fprintf(stderr, "Switching to mail.\n");
} else {
spec.fCreator = 'CSOm';
PLstrcpy(spec.name, "\pEudora");
fprintf(stderr, "Switching to Eudora.\n");
}
}
if (err == noErr) {
OSStatus lsErr;
FSRef appRef;
CFStringRef appName;
appName = CFStringCreateWithPascalString(NULL, spec.name,
kCFStringEncodingMacHFS);
assert(appName != NULL);
lsErr = LSFindApplicationForInfo(spec.fCreator, NULL, appName,
&appRef, NULL );
if (lsErr != noErr) {
fprintf(stderr, "*** This probably isn't going to work.\n"
);
}
CFRelease(appName);
}
if (err == noErr) {
err = ICSetPref(inst, "\pHelper*mailto", kICAttrNoChange,
&spec, sizeof(spec));
}
if (err == noErr) {
size = sizeof(newSpec);
err = ICGetPref(inst, "\pHelper*mailto", &junkAttr, &newSpec,
&size);
}
if (err == noErr) {
if (newSpec.fCreator != spec.fCreator) {
fprintf(stderr, "*** Change did not stick.\n");
}
}
junk = ICStop(inst);
assert(junk == noErr);
}
if (err == noErr) {
fprintf(stderr, "Success.\n");
} else {
fprintf(stderr, "Failed with error %ld.\n", err);
}
fprintf(stderr, "Done. Press command-Q to Quit.\n");
}
----------------------------------------------------------------------------
-- Quinn "The Eskimo!" <http://www.apple.com/developer/
>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
Mit freundlichen Gr|_en
Christian Weykopf
--
Meilenstein Software GmbH
Neue Strasse 5
D-31582 Nienburg
Tel: +49 (0) 5021 91 24 44
Fax: +49 (0) 5021 91 24 45
http://www.meilenstein.de/
mailto:email@hidden
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.