Re: Close System Preferences programmatically

2011-01-04 Thread Peter Lübke


Am 04.01.2011 um 23:38 schrieb eveningnick eveningnick:

- If you really want System Preferences to quit, you could use  
NSAppleScript

and do something like:
tell application "System Preferences" to quit
You can do the same using AppleEvents.


Peter, could you hint me on how to do it using AppleEvents?

Googling, i have found some references to OmniAppKit:
"There's a working example of using Apple Events to do this in the
published Omni frameworks --- let's see, it's OAOpenSystemPreferences
(), in OAPreferenceController.m, in OmniAppKit."

I havent found this kit though, it is quite outdated.




Here are two very simple code samples that terminate an application  
friendly by sending it an apple event.

They do exactly the same as pressing an app's "Quit" - menu item.
(Use at your own risk!)

// Terminate an application specified by a bundle identifier.
// Returns a BOOL value indicating the success of the operation.
- (BOOL)quitApplicationWithBundleIdentifier:(const char *) 
bundleIdentifier

{
OSErr err;
AppleEvent quitEvent;

AEInitializeDesc(&quitEvent);

err = AEBuildAppleEvent( kCoreEventClass, kAEQuitApplication,
	typeApplicationBundleID, bundleIdentifier, strlen 
(bundleIdentifier),


kAutoGenerateReturnID, kAnyTransactionID,
&quitEvent, NULL, 
"from:null()");

if ( err == noErr )
err = AESendMessage(&quitEvent, NULL, kAENoReply, 
kAEDefaultTimeout);

AEDisposeDesc(&quitEvent);

return ( err == noErr );
}

// Terminate an application specified by a Process Serial Number.
// Returns a BOOL value indicating the success of the operation.
- (BOOL)quitApplicationWithProcessSerialNumber:(ProcessSerialNumber)PSN
{
OSErr err;
AppleEvent quitEvent;

AEInitializeDesc(&quitEvent);

err = AEBuildAppleEvent( kCoreEventClass, kAEQuitApplication,

typeProcessSerialNumber, &PSN, sizeof(PSN),

kAutoGenerateReturnID, kAnyTransactionID,
&quitEvent, NULL, 
"from:null()");

if ( err == noErr )
err = AESendMessage(&quitEvent, NULL, kAENoReply, 
kAEDefaultTimeout);

AEDisposeDesc(&quitEvent);

return ( err == noErr );
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Kyle Sluder
2011/1/4 eveningnick eveningnick :
>> - If you really want System Preferences to quit, you could use NSAppleScript
>> and do something like:
>> tell application "System Preferences" to quit
>> You can do the same using AppleEvents.
>
> Peter, could you hint me on how to do it using AppleEvents?
>
> Googling, i have found some references to OmniAppKit:
> "There's a working example of using Apple Events to do this in the
> published Omni frameworks --- let's see, it's OAOpenSystemPreferences
> (), in OAPreferenceController.m, in OmniAppKit."
>
> I havent found this kit though, it is quite outdated.

https://github.com/omnigroup/OmniGroup/blob/master/Frameworks/OmniAppKit/Preferences.subproj/OAPreferenceController.m#L989

OmniAppKit is used in all of our desktop apps.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Murat Konar
Leaving aside for the moment the wisdom of all this...

Preference panes run in the same process as the System Preferences application. 
That means they can directly call methods of the objects that make up System 
Preferences.

A simple way to get System Preferences to "Show All" is to simply call whatever 
object/method is targeted by the "Show All" menu item. Would work for "Quit" as 
well.

So you grab the menubar, scan the menu items until you find what you need, grab 
the target and action in said menu item, and just call it.

Now about the wisdom part: depending on what your definition of "uninstall" is, 
"Show All" may not get you what you need. For example, if "uninstall" means 
simply moving all your files to the trash or deleting them, that will not be 
enough. You will first have to get System Preferences to unload your bundle. 
That's not going to be very straightforward, unless you use your "force System 
Preferences to quit" strategy, which as mentioned already is not the best user 
experience.

_murat

On Jan 4, 2011, at 2:11 PM, Peter Lübke wrote:

> Though almost everybody seems to disagree you should do something like this 
> here some ideas:
> 
> - If you want to press the "Show All"- or "Back"- button, you could do this 
> using the Accessibility API; take a look at Apple's "Accessibility Inspector" 
> app.
> 
> - If you really want System Preferences to quit, you could use NSAppleScript 
> and do something like:
>   tell application "System Preferences" to quit
> You can do the same using AppleEvents.
> 
> If your app didn't open System Preferences programmatically before, I'd 
> strongly suggest you ask the user if quitting is ok.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
> - If you really want System Preferences to quit, you could use NSAppleScript
> and do something like:
> tell application "System Preferences" to quit
> You can do the same using AppleEvents.

Peter, could you hint me on how to do it using AppleEvents?

Googling, i have found some references to OmniAppKit:
"There's a working example of using Apple Events to do this in the
published Omni frameworks --- let's see, it's OAOpenSystemPreferences
(), in OAPreferenceController.m, in OmniAppKit."

I havent found this kit though, it is quite outdated.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Dave DeLong
s/installer/uninstaller/

Dave

On Jan 4, 2011, at 2:14 PM, Dave DeLong wrote:

> Another option would be to have your preference pane launch a little 
> installer that won't proceed until the user quits System Preferences.  
> Something like "In order to uninstall MyAwesomeFoo, please quit System 
> Preferences".  Then wait until the app quits, then dismiss the dialog and 
> proceed.  You might even be nice and have a "Quit it for me" button, that 
> does the AppleScript thing.
> 
> Dave
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Dave DeLong
Another option would be to have your preference pane launch a little installer 
that won't proceed until the user quits System Preferences.  Something like "In 
order to uninstall MyAwesomeFoo, please quit System Preferences".  Then wait 
until the app quits, then dismiss the dialog and proceed.  You might even be 
nice and have a "Quit it for me" button, that does the AppleScript thing.

Dave

On Jan 4, 2011, at 2:11 PM, Peter Lübke wrote:

> Though almost everybody seems to disagree you should do something like this 
> here some ideas:
> 
> - If you want to press the "Show All"- or "Back"- button, you could do this 
> using the Accessibility API; take a look at Apple's "Accessibility Inspector" 
> app.
> 
> - If you really want System Preferences to quit, you could use NSAppleScript 
> and do something like:
>   tell application "System Preferences" to quit
> You can do the same using AppleEvents.
> 
> If your app didn't open System Preferences programmatically before, I'd 
> strongly suggest you ask the user if quitting is ok.
> 
> Peter
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Peter Lübke
Though almost everybody seems to disagree you should do something  
like this here some ideas:


- If you want to press the "Show All"- or "Back"- button, you could  
do this using the Accessibility API; take a look at Apple's  
"Accessibility Inspector" app.


- If you really want System Preferences to quit, you could use  
NSAppleScript and do something like:

tell application "System Preferences" to quit
You can do the same using AppleEvents.

If your app didn't open System Preferences programmatically before,  
I'd strongly suggest you ask the user if quitting is ok.


Peter

Am 04.01.2011 um 22:20 schrieb eveningnick eveningnick:


Hi Nick
Thank you
I've an unusual application that is mainly located in System
Preferences (its gui part), and which can be uninstalled by clicking a
button "Uninstall" in that prefpane

better solution would be to programmatically press "Show All" button
("back" in System Preferences), but that seems impossible because
PrefPane reference doesnt mention have to do that.

if someone knows there is a way to click "Show All" from a preference
pane programmatically, i'd be thankful


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread John Joyce

On Jan 4, 2011, at 3:20 PM, eveningnick eveningnick wrote:

> Hi Nick
> Thank you
> I've an unusual application that is mainly located in System
> Preferences (its gui part), and which can be uninstalled by clicking a
> button "Uninstall" in that prefpane
> 
> better solution would be to programmatically press "Show All" button
> ("back" in System Preferences), but that seems impossible because
> PrefPane reference doesnt mention have to do that.
> 
> if someone knows there is a way to click "Show All" from a preference
> pane programmatically, i'd be thankful
> ___
> 

Definitely just ask the user to Quit System Preferences if it is running.
With all that you seem to be doing there, it may be better to just have a stand 
alone uninstaller.
If an app *really* requires an installer/uninstaller, then it it is not so 
trivial to install/uninstall.
An app that does the status-menu-item, managed-by-system-preferences-pane 
thing, that should have a separate uninstaller.

The only way it's going to be easier is to have an app that is drag and drop 
install/uninstall.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Murat Konar
Since you can't reload bundles, you might need to quit System Preferences as 
part of a preference pane's self-updating scheme.

But it's probably better to just ask the user to do it.

_murat

On Jan 4, 2011, at 1:08 PM, Nick Zitzmann wrote:

> 
> On Jan 4, 2011, at 1:56 PM, eveningnick eveningnick wrote:
> 
>> Is it possible to close System  Preferences programmatically from
>> within a custom preference pane?
> 
> Yes.
> 
>> What would be the correct way?
> 
> You could just call -[NSApplication terminate:], though I'm wondering why 
> you'd want to programmatically quit System Preferences, since that seems like 
> an odd thing to do unless an unrecoverable error occurred or something like 
> that.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Kyle Sluder
On Tue, Jan 4, 2011 at 12:56 PM, eveningnick eveningnick
 wrote:
> Is it possible to close System  Preferences programmatically from
> within a custom preference pane? What would be the correct way?
> Is it possible to programmatically press button "Show all"?

You should never need to do either of those things.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
Hi Nick
Thank you
I've an unusual application that is mainly located in System
Preferences (its gui part), and which can be uninstalled by clicking a
button "Uninstall" in that prefpane

better solution would be to programmatically press "Show All" button
("back" in System Preferences), but that seems impossible because
PrefPane reference doesnt mention have to do that.

if someone knows there is a way to click "Show All" from a preference
pane programmatically, i'd be thankful
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Close System Preferences programmatically

2011-01-04 Thread Nick Zitzmann

On Jan 4, 2011, at 1:56 PM, eveningnick eveningnick wrote:

> Is it possible to close System  Preferences programmatically from
> within a custom preference pane?

Yes.

> What would be the correct way?

You could just call -[NSApplication terminate:], though I'm wondering why you'd 
want to programmatically quit System Preferences, since that seems like an odd 
thing to do unless an unrecoverable error occurred or something like that.

Nick Zitzmann
<http://www.chronosnet.com/>

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Close System Preferences programmatically

2011-01-04 Thread eveningnick eveningnick
Is it possible to close System  Preferences programmatically from
within a custom preference pane? What would be the correct way?
Is it possible to programmatically press button "Show all"?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com