Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Determine whether screensaver is running

Determine whether screensaver is running
Thread Tools
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 21, 2002, 02:19 PM
 
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?
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 21, 2002, 08: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  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 21, 2002, 09:18 PM
 
sysctl sounds fine, thanks for the tip. sounds feasable after having read some documentation.
     
Forum Regular
Join Date: Sep 2000
Location: UK
Status: Offline
Reply With Quote
Jul 22, 2002, 01: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)setScreenSaverCanRunBOOL)fp12;
- (void)screenSaverStartNow;
- (void)screenSaverStopNow;
- (void)restartForUser:fp12;
- (double)screenSaverTimeRemaining;

@end

Call this when you need to know:

[[ScreenSaverController controller] screenSaverIsRunning]
     
seb2  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 22, 2002, 01: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 ...
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 22, 2002, 03: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)setScreenSaverCanRunchar)fp19;
- (char)screenSaverCanRun;
- (char)screenSaverIsRunning;
@end</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
     
seb2  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 22, 2002, 03:36 PM
 
thanks to both of you, guys!

i know why i love these forums and i know why i love cocoa! awesome!
     
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jul 23, 2002, 05:52 PM
 
Is there a programmatic method for enabling/disabling the password protection feature of the screen saver?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -4. The time now is 02:35 AM.
All contents of these forums © 1995-2015 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2015, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2