민서네집

[mac] 최대 절전 모드 (Hibernate) 본문

Mac

[mac] 최대 절전 모드 (Hibernate)

브라이언7 2013. 3. 29. 23:50

How to enable hibernate mode on a Mac


Hibernation Tool for Mac OS

위 웹페이지에서 Hibernation Tool for Mac OS를 Download 받아 설치하면 에러를 내면서 안 되는데, Lion 운영체제부터 전원관리 옵션을 바꾸려면 관리자 권한이 필요하게 되었나 보다.

Finder에서 Hibernate.app 선택하고 마우스 우클릭해서 "Show Package Contents"를 선택한다.

/Applications/Hibernate.app/Contents/ 경로로 들어가서 main.scpt 파일을 더블클릭해서 AppleScript Editor에서 연다.


————————————————————————————-
do shell script “/usr/bin/pmset force -a hibernatemode 1″
ignoring application responses
tell application “System Events” to sleep
delay 5
do shell script (“/usr/bin/pmset force -a hibernatemode ” & lastMode)
end ignoring
————————————————————————————-


를 다음과 같이 수정한다.


—————————————————————————————————
do shell script “/usr/bin/pmset force -a hibernatemode 25″ user name “{USER NAME}” password “{PASSWORD}” with administrator privileges

ignoring application responses

tell application “System Events” to sleep
delay 30
do shell script (“/usr/bin/pmset force -a hibernatemode ” & lastMode) user name “{USER NAME}” password “{PASSWORD}” with administrator privileges
end ignoring
—————————————————————————————————


이 스크립트는 현재의 hibernatemode를 save 하고, hibernatemode 를 25로 강제로 바꾸고 delay 를 줘서 sleep(Hibernate) 에 들어가고, 나중에 사용자에 의해 sleep(Hibernate) 에서 깨어난 후, 원래 있던, 저장해 둔 hibernatemode 값을 복원하는 스크립트의 일부분이다.

그런데 원래 코드처럼 delay 5(초)로 주면, hibernate 모드로 들어가기 전에 원래 상태(default hibernatemode 3)로 돌아가기 때문에 hibernate 모드가 되지 않는다. 그래서 delay 30(초)로 주었다. (내 MacBook Pro 노트북이 hibernate로 들어가는데 26초 정도 걸린다.)

“exit return_code = 0xe00002c1″ 에러가 나는 이유가 관리자 권한이 없기 때문이다.
그래서 with administrator privileges 라고 붙여주면 되는데, 암호를 물어보는 prompt 가 뜬다.
이 prompt 를 안 뜨게 하려면, user name "{USER NAME}" password "{PASSWORD}" 를 붙여주면 된다.

[2014-10-18]
OS X 10.10 Yosemite로 업그래이드 하고 나서 Hibernate로 안되서 아래와 같이 다시 코드를 수정했다.
hibernatemode를 원래값으로 복구하기 전에 display 창을 띄워서 30초 동안 대기하게 했다.
이렇게 안하고 그냥 delay 30을 하면 Yosemite에서는 Hibernate 되기 전에 다시 hibernatemode가 원래값으로 되돌아가서 Hibernate가 안된다. delay를 120 까지도 늘려봤지만 Hibernate 되지 않았다.

display dialog 명령문 뒤에 giving up after 30 을 준 것은 30초 후에 자동으로 창을 닫고 default value 를 리턴하기 위함이다.
[참고]

"Do you want to hibernate?" Dialog 창은 안 띄워도 될 것 같아서 주석처리했다. 왜냐하면 처음 대기 모드로 들어가고 나서 몇 초 동안은 키보드의 어떤 키라도 치거나 트랙패드를 클릭하면 대기 모드로 들어가는 것이 취소되기 때문이다. 

-- -- Simple hibernate script -- (no administrative rights necessary) -- by Sven Anderson (sven AT anderson.de) -- -- partly based on "SafeSleep" by Tomis Erwin -- set lastMode to -1 set theList to every paragraph of (do shell script "pmset -g") repeat with anItem in theList if anItem contains "hibernatemode" then set lastMode to (word 2 of anItem) as number exit repeat end if end repeat if lastMode = -1 then display dialog "Hibernation is currently not enabled on this machine." buttons "OK" default button 1 cancel button 1 return end if --display dialog ("Do you want to hibernate?" & return & "(suspend-to-disk)") with icon 1 giving up after 5 do shell script "/usr/bin/pmset force -a hibernatemode 25" user name "Administrator_Account" password "PASSWORD" with administrator privileges ignoring application responses tell application "System Events" to sleep end ignoring delay 5 display dialog ("hibernatemode" & return & "(to default value)") buttons "OK" default button 1 giving up after 30 do shell script ("/usr/bin/pmset force -a hibernatemode " & lastMode) user name "Administrator_Account" password "PASSWORD" with administrator privileges # http://blog.kaputtendorf.de/2007/08/17/hibernation-tool-for-mac-os/ # do shell script "/usr/bin/pmset sleepnow" # This script was modified by Heeseok Kang to adapt to OS X 10.10 Yosemite. # http://bryan7.tistory.com/59


Hibernate (최대절전모드)로 들어가기 위해서 좀 더 좋은 방법이 있었다.

처음부터 무조건 Hibernate 되기 보다는 일정 시간 이내에는 sleep 되고, 그 이후에는 Hibernate 되는게 더 좋다.

이런 기능이 별도의 App이나 Action Script를 사용하지 않아도 OS X 자체 기능 만으로도 된다.

Terminal App에서 pmset -g 하면 전원관리에 관련된 여러 옵션의 설정값을 볼 수 있다.

[참고]  Terminal App에서  man pmset 입력.

“standby” causes kernel power management to automatically hibernate a machine after it has slept for a specified time period. This saves power while asleep.


“standbydelay” specifies the delay, in seconds, before writing the hibernation image to disk and powering off memory for Standby.


Terminal App에서 다음을 입력한다.


——————————————————————
sudo pmset -a hibernatemode 3 standby 1 standbydelay 600
——————————————————————


위 명령은 “standby”를 설정하고, sleep 되고 나서 600초 지나고 나서 Hibernate (최대절전모드)로 들어가도록 설정한다.





Mac OS X hibernation


SmartSleep

- have your Mac sleep smart (7,052원)


SafeSleep 

- free. 잘 작동한다. Terminal 에서 설정하는 hibernatemode를 App으로 설정하는 것뿐 다른 기능은 없다.


내가 원하는 것은 Windows 에서처럼 Sleep 모드로 있다가 일정 시간이 지나면 최대절전모드로 들어가는 기능을 원했는데, 웹을 여기저기 찾아봐도 이런 기능을 하는 App을 찾을 수 없었다.

Make my Macbook Pro Hibernate


Terminal 에서 

pmset -g | grep hibernate  을 해보면
 hibernatefile /var/vm/sleepimage
 hibernatemode 3

내 맥북의 기본 설정은 hibernatemode 3 이었다.

  • 0 – Legacy sleep mode. It will save everything to RAM upon sleeping but does not support “Safe Sleep”. Very fast sleep.
  • 1 – Legacy “Safe Sleep”. This is the “Safe Sleep”. Everything your laptop goes into sleep, it will save everything to harddisk. Slow on Sleep and Startup.
  • 3 – Default. As described above, when sleeping, contents are saved to RAM. When battery runs out, hibernate occurs.
  • 5 – Behaves as 1 but applicable only for modern Mac that uses “Secure virtual memory”.
  • 7 – Behaves as 3 but applicable only for modern Mac that uses “Secure virtual memory”.
이 설정을 1번으로 바꾸면 Sleep을 할 때마다 최대 절전 모드로 사용할 수 있다.

$ alias hibernate="sudo pmset -a hibernatemode 1"
$ hibernate
Password:
$ pmset -g | grep hibernate 
 hibernatefile   /var/vm/sleepimage
 hibernatemode 1

[참고] 어느 웹페이지에서 본 내용인데, hibernatemode 25 는 hibernatemode 1 과 유사한데, 좀 더 적은 양을 하드디스크에 저장해서, 복구할 때도 hibernatemode 1보다 좀 더 빠르다고 한다.

Comments