MacNN Forums (http://forums.macnn.com/)
-   Developer Center (http://forums.macnn.com/developer-center/)
-   -   Determine whether screensaver is running (http://forums.macnn.com/79/developer-center/83032/determine-whether-screensaver-is-running/)

 
seb2 Jul 21, 2002 01:19 PM
Determine whether screensaver is running
hi everybody,

i think the topic says it all... is there a way?

i thought about doing a "ps" from an nstask and see whether "/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app" was among the running processes but i figured this was not very elegant -- is there a better way?

any ideas?
 
Angus_D Jul 21, 2002 07:02 PM
I think you're probably going to have to do that, yeah, but you should probably use Carbon's Process Manager or sysctl to determine if it's running or not. I think that's a nicer solution than running ps from an NSTask, personally :)
 
seb2 Jul 21, 2002 08:18 PM
sysctl sounds fine, thanks for the tip. sounds feasable after having read some documentation. :)
 
calumr Jul 22, 2002 12:08 PM
By the magic of class-dump (see fink), add this to your source somewhere:

@interface ScreenSaverController:NSObject <ScreenSaverControl>
{
NSConnection *_connection;
id _daemonProxy;
void *_reserved;
}

+ controller;
+ monitor;
+ daemonConnectionName;
+ daemonPath;
+ enginePath;
- init;
- (void)dealloc;
- (void)_connectionClosed:fp12;
- (BOOL)screenSaverIsRunning;
- (BOOL)screenSaverCanRun;
- (void)setScreenSaverCanRun:(BOOL)fp12;
- (void)screenSaverStartNow;
- (void)screenSaverStopNow;
- (void)restartForUser:fp12;
- (double)screenSaverTimeRemaining;

@end

Call this when you need to know:

[[ScreenSaverController controller] screenSaverIsRunning]
 
seb2 Jul 22, 2002 12:40 PM
woohoo, sounds great!

but... i'm sorry, i've never used any class-dumps in my own source code before... it complains it cannot find the protocol declaraction for "screensavercontrol" -- i tried linking against the screensaver framework, the only idea i've had, but... no success. a recursive grep for the declaration in /system/library/frameworks/screensaver.framework didn't turn up anything, either.

could you help me once again with my stupidity, please?

...i guess i'll never be a good programmer :( ...
 
Angus_D Jul 22, 2002 02:17 PM
You haven't declared the ScreenSaverControl protocol in any headers, but referred to it in the declaration for ScreenSaverController, so the compiler is getting confused. You don't have to fully declare classes anyway, so just to keep the compiler happy you could do:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">// hack definition for private class
@interface ScreenSaverController:NSObject
+ controller;
- (BOOL)screenSaverIsRunning;
@end</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Or you could just declare the ScreenSaverControl category, which is:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">@protocol ScreenSaverControl
- (double)screenSaverTimeRemaining;
- (void)restartForUser:fp16;
- (void)screenSaverStopNow;
- (void)screenSaverStartNow;
- (void)setScreenSaverCanRun:(char)fp19;
- (char)screenSaverCanRun;
- (char)screenSaverIsRunning;
@end</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
 
seb2 Jul 22, 2002 02:36 PM
thanks to both of you, guys!

i know why i love these forums and i know why i love cocoa! awesome!
 
LordJavac Jul 23, 2002 04:52 PM
Is there a programmatic method for enabling/disabling the password protection feature of the screen saver?
 
All times are GMT -4. The time now is 07:56 AM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2015, vBulletin Solutions, Inc.


Content Relevant URLs by vBSEO 3.3.2