Y a-t-il un événement déclenché lorsque l'économiseur d'écran démarre? Comme pour le verrouillage de porte-clés:mac screensaver start event
OSStatus keychain_locked(SecKeychainEvent keychainEvent, SecKeychainCallbackInfo *info, void *context){...}
Y a-t-il un événement déclenché lorsque l'économiseur d'écran démarre? Comme pour le verrouillage de porte-clés:mac screensaver start event
OSStatus keychain_locked(SecKeychainEvent keychainEvent, SecKeychainCallbackInfo *info, void *context){...}
enfin trouvé - la solution est d'utiliser NSDistributedNotificationCenter et observer
événements ci-Comme
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self
selector:@selector(screensaverStarted:)
name:@"com.apple.screensaver.didstart"
object:nil];
Bien qu'il n'y ait pas d'événement de carbone pour cela, vous peut être averti lorsque les changements d'application en cours, puis vérifier pour voir si la nouvelle application est le processus d'économiseur d'écran.
// Register the event handler for when applications change
{
EventTypeSpec es;
es.eventClass = kEventClassApplication;
es.eventKind = kEventAppFrontSwitched;
InstallApplicationEventHandler(&appChanged, 1, &es, NULL, NULL);
}
OSStatus appChanged(EventHandlerCallRef nextHandler, EventRef anEvent, void* userData)
{
ProcessSerialNumber psn;
GetEventParameter(anEvent, kEventParamProcessID, typeProcessSerialNumber,
NULL, sizeof(psn), NULL, &psn);
// Determine process name
char procName[255];
{
ProcessInfoRec pInfo;
Str255 procName255;
FSRef ref;
pInfo.processInfoLength = sizeof(ProcessInfoRec);
pInfo.processName = procName255;
pInfo.processAppRef = &ref;
GetProcessInformation(&psn, &pInfo);
const unsigned int size = (unsigned int)procName255[0];
memcpy(procName, procName255 + 1, size);
procName[size] = '\0';
}
if(strcmp(procName, "ScreenSaverEngine") == 0)
{
NSLog(@"Found %s\n", procName);
}
return noErr;
}
Ce n'est pas exactement une réponse à la question, mais j'ai passé beaucoup de temps à chercher en vain une liste des notifications affichées par OS X, donc je voulais poster du code que j'ai écrit pour la découverte de notification.
Le code signe tout simplement écouter toutes notifications, et imprime quelques informations pour chacun comme il vient.
import Foundation
let distCenter = CFNotificationCenterGetDistributedCenter()
if distCenter == nil {
exit(1)
}
CFNotificationCenterAddObserver(distCenter, nil, { (center, observer, name, object, userInfo) -> Void in
print("Event occurred: \(name) User info: \(userInfo)")
}, nil, nil, .DeliverImmediately)
CFRunLoopRun()