Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Mac OSX Terminal – Turn off system sleep

Posted on April 4, 2016April 4, 2016 By David Kittell

If you use a Mac whether true server or a Mac Mini for a server this script below is very helpful to prevent the Mac from falling asleep and preventing the machine from being a server.

# Disable Computer Sleep
sudo systemsetup -setcomputersleep Off 
sudo systemsetup -getcomputersleep 

# Disable Computer Safe Sleep
sudo pmset -a hibernatemode 0
sudo nvram "use-nvramrc?"=false

# Remove Sleep Image
sudo rm /private/var/vm/sleepimage

If all of this still does not do it you can try to caffeinate your mac

caffeinate -t 144000 &

To re-enable sleep settings

# Enable Computer Sleep after 60 minutes
sudo systemsetup -setcomputersleep 60
sudo systemsetup -getcomputersleep 

# Enable Computer Safe Sleep
sudo pmset -a hibernatemode 3
sudo nvram "use-nvramrc?"=true

References:

  • http://osxdaily.com/2015/02/03/set-or-disable-sleep-due-to-mac-system-inactivity-from-the-command-line-in-os-x/
  • https://www.recoveryforce.com/how-to-disable-safe-sleep-in-macos-10/
  • http://osxdaily.com/2012/08/03/disable-sleep-mac-caffeinate-command/
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Mac OS X Shell Mac OSX UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Remote Desktop Port Change

Posted on July 18, 2013October 26, 2015

‘Kelly Theriot 11-2004 ‘Kelly’s Korner Option Explicit Set ws = WScript.CreateObject("WScript.Shell") Dim ws, t, p1, n, cn, MyBox, vbdefaultbutton Dim itemtype p1 = "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp" n = ws.RegRead(p1 & "PortNumber") t = "Change Port Number" cn = InputBox("Type in the new port number", t, n) If cn <> "" Then…

Read More

Find Most Expensive Queries Using DMV

Posted on April 29, 2013October 26, 2015

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset / 2) + 1, ( ( CASE qs.statement_end_offset WHEN – 1 THEN DATALENGTH(qt.TEXT) ELSE qs.statement_end_offset END – qs.statement_start_offset ) / 2 ) + 1) ,qs.execution_count ,qs.total_logical_reads ,qs.last_logical_reads ,qs.total_logical_writes ,qs.last_logical_writes ,qs.total_worker_time ,qs.last_worker_time ,qs.total_elapsed_time / 1000000 total_elapsed_time_in_S ,qs.last_elapsed_time / 1000000 last_elapsed_time_in_S ,qs.last_execution_time ,qp.query_plan FROM sys.dm_exec_query_stats qs CROSS…

Read More

GetUserDetails

Posted on February 21, 2013October 26, 2015

public static string GetUserDetails(string stringInput, int displayoption) { if (stringInput == "") { return strErrorMessage_GetUserDetails; } else { string strUserName = ""; string strName = ""; string strReturnString = ""; string query1 = "SELECT user_name, first_name, last_name FROM users where user_id = ‘" + stringInput + "’"; // strReturnString =…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes