2012-12-06 3 views
3

osx가 절전 모드로 전환 될 때 및 절전 모드에서 다시 시작될 때를 감지 할 수있는 파이썬 프로그램을 작성할 수 있습니까?osx가 절전 모드에서 잠/재개 할 때를 감지합니다.

내가 이것을 연구하지 않은 것처럼 들리는 경우 사과드립니다. 나는 편안함을 벗어 났으며, Python에서 이것을보고 할 수있는 C로 작성된 것으로 위임 할 필요가 있는지 확신 할 수 없거나 불필요합니다.

답변

3

IOKit에서이 작업을 수행 할 수있는 도구가 있습니다. 특히 IORegisterForSystemPower()으로 등록 된 콜백은 시스템이 대기 상태가되기 직전에 호출되고 깨어 난 직후에 호출됩니다.

bb's sleepwatcher daemon은 시스템 절전/종료와 같은 다양한 이벤트가 발생할 때 지정하는 명령을 호출 할 수 있으며 다양한 다른 이벤트 (절전/대기 모드, 시스템 유휴 상태, 시스템 종료 표시 등)를 호출 할 수 있습니다. ..). 이 샘플 코드는 여기에 애플의 문서에서 발췌 한 것입니다 NSWorkspaceDidWakeNotification

- (void) receiveSleepNote: (NSNotification*) note 
{ 
    NSLog(@"receiveSleepNote: %@", [note name]); 
} 

- (void) receiveWakeNote: (NSNotification*) note 
{ 
    NSLog(@"receiveWakeNote: %@", [note name]); 
} 

- (void) fileNotifications 
{ 
    //These notifications are filed on NSWorkspace's notification center, not the default 
    // notification center. You will not receive sleep/wake notifications if you file 
    //with the default notification center. 
    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self 
      selector: @selector(receiveSleepNote:) 
      name: NSWorkspaceWillSleepNotification object: NULL]; 

    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self 
      selector: @selector(receiveWakeNote:) 
      name: NSWorkspaceDidWakeNotification object: NULL]; 
} 

에 대한

+0

건배 - sleepwatcher은 매우 간단한 해결책처럼 보인다 :) –

관련 문제