31 Days Of OS X Tips: Keep Your Mac From Sleeping Using The Terminal

Caffeine is a useful utility that keeps your Mac awake when activated—useful if you want to prevent your Mac from sleeping so it can carry out a specific task. But you don’t need to download a third-party app in order to do the deed: Instead, you can simply use a Terminal command to replicate the function.

  1. Open the Terminal app. (Applications/Utilities/Terminal.app)
  2. Enter Caffeinate & into the Terminal then press the Return key.
  3. If you want to prevent your Mac from sleeping for a certain length of time, use the modifier -t  between Caffeinate and &, like so:
    Caffeinate -t 7200 &

    The Caffeinate command-line tool requires you to enter the duration in seconds, so in this example, we want our Mac to stay awake for 7200 seconds, or two hours. If you don’t have your hours-to-seconds unit conversions memorized, you can always type a query like “2 hours in seconds” into Spotlight to get an instant unit conversion.

  4. You can also set this up as an Automator Trigger or Shell Script. There are additional options you can find by entering man caffeinate in the Terminal.

Source: Brett Terpstra

Mac geek? Gamer? Why not both? Mike is a writer from Wisconsin who enjoys wasting immense amounts of time on the Internet. You can follow him on Twitter.