Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iemcj

macrumors 6502
Original poster
Oct 31, 2015
488
173
I have some downloads I need to finish that are going to take a long time. On my older MBP I can set the screen to time out after a few minutes but have the actual computer stay awake for a longer amount of time. For some reason on this 16" MPB under the energy saver there is JUST ability to turn the display off after a certain amount of time. And whenever that happens and I come back to the computer, the download has stopped and now I need to restart everything. I'd prefer not to leave the display on the entire night and shorten it's life but I need it to stay on at all times. Thanks!
 
Don’t have a 16”, but if the brightness slider is the same you could always just set brightness to 0 which should turn off the display panel, while keeping the computer going. Alternatively check if the Hot Corner option for display sleep is purely display sleep or that also stops the downloads
 
  • Like
Reactions: iemcj
Hi eimcj,

Yes, as suggested by Steve121178, the Amphetamine.app may be the solution to your display sleep issue. But there are also macOS utilities that can solve your problem.

For instance, you might simply set the display off timer in the System Preferences Energy Saver pane to a small number, say 1 min, and then the display will turn off after 1 min. If you have checked the "Prevent computer from sleeping automatically when the display is off" box, then the display will turn off without the computer sleeping.

Personally, I use the "caffeinate" Terminal command to keep the computer awake while allowing the displays (both internal display on a MBP as well as an external monitor) to turn off.

You might also check out the "pmset" command to control the display and computer sleep modes.

I have written a small shell script that takes a second shell script filename as an argument. The first script then executes the second script, determines second script's process ID, and caffeinates the second script's process. In this way the computer will not go to sleep while the second script is executing but still allowing the displays to turn off after their timeout period.

In your particular usage, the second script would perform the downloads that take a long time, while the caffeinated script keeps the computer from sleeping during the downloads but the displays still turn off.

Just thought I'd offer an alternative solution...

Solouki

P.S. If you are interested, I could upload my caffeinate shell script that takes the second shell script filename as an argument?
 
  • Like
Reactions: simonmet
I set the screen to sleep when I move the mouse cursor to the lower-right corner of the screen, under System Preferences -> Desktop and Screensaver -> Hot Corners...

Then I make sure the checkbox "Prevent the computer from sleeping automatically when the display is off" is off under System Preferences -> Energy Saver -> Power Adapter tab.

That lets me shut the screen off while keeping the system running on my 16" MBP. I actually just did that last night to let iCloud load ~7,000 photos up. Worked great.
 
  • Like
Reactions: astrorider
I'm writing this from my Mini, not my MacBook (so I'm wondering if the energy saver options may be different), but... try this:

1. Open the desktop and screen saver preference pane

2. Click "screen saver"

3. On the left, select the screen saver you want

4. On the lower right, pick a "hot corner" (I prefer the upper right)

5. That sets the screen saver. Check it to be sure.

NOW...

6. Go to the energy saver preference pane.

7. Do you have an option "prevent computer from sleeping automatically when the display is off" ???

8. If so, put a checkmark into it.

Set up this way, with the lid open, I believe you can now invoke the screen saver AND prevent the MacBook from sleeping.

See if this works for you, and please get back to us if it does.

(I will guess that this doesn't work IF you "close the lid", which may put the MBP to sleep anyway...)
 
I have some downloads I need to finish that are going to take a long time. On my older MBP I can set the screen to time out after a few minutes but have the actual computer stay awake for a longer amount of time. For some reason on this 16" MPB under the energy saver there is JUST ability to turn the display off after a certain amount of time. And whenever that happens and I come back to the computer, the download has stopped and now I need to restart everything. I'd prefer not to leave the display on the entire night and shorten it's life but I need it to stay on at all times. Thanks!
There’s an option somewhere in display or energy saver settings called “hot corners”. I set the bottom left corner to put the display to sleep - so all I have to do is put the cursor in the bottom left corner and the display turns off. Move the mouse again and it’s back. I’ve been doing this since I got my 2011 MacBook Pro new! Works great.
 
Yes please

Hi casperes1996,

I hope the following shell script is helpful...

I had originally written a script for the Sun Microsystem's Solaris OS to perform a similar task, and later modified it for Apple's Mac OS-es. In 2012 I converted the script to use Apple's "caffeinate" utility. I believe that this script will execute most any other shell script that you'd like to run while preventing sleep mode from happening. It performs this task by executing the shell script whose name you include on the command line as an argument to the "caffeinated-script.sh" script, then it determines the PID of the process associated with this execution and "caffeinate"s that process. When the shell script completes its execution, the caffeinate process terminates allowing for the computer to then go to sleep after the execution of the shell script. I find this useful for running long numerical computations or building code or LaTeX-ing large documents.

You would use this script at a Terminal prompt by the following:

. caffeinate-script.sh <name of shell script to execute and caffeinate>

Because the MacRumors "Attach files" button does not allow shell scripts to be attached, I renamed the shell script to "caffeinate-script.sh.txt" in order to attach it. You will need to rename it back to "caffeinate-script.sh" and change the permissions to 755, that is, at a Terminal prompt:

mv caffeinate-script.sh.txt caffeinate-script.sh
chmod 755 caffeinate-script.sh

You will also need to change the permissions to 755 on the shell script that you'd like to caffeinate:

chmod 755 <name of shell script to execute and caffeinate>

If you have any questions, or if the script doesn't work for you, let me know.

Solouki

Attachment: caffeinate-script.sh.txt
-------------------------------------------------------------------------------

Hummm...the "Attach files" button did not work for me. I tried to attached a regular ASCII text file with an extension of .txt but this did not work. Maybe you could help me? (I have done this before --- but probably over a year ago.)

I also tried "cut-and-paste"-ing the shell script into this post, but when I went to post it, it came back with an "Oops..." error saying that an error was encountered.
 
Last edited:
Click the apple logo and lock screen. Your screen will black based on your settings but the computer will not go to sleep.
 
  • Like
Reactions: tCC_
Hi casperes1996,

I hope the following shell script is helpful...

I had originally written a script for the Sun Microsystem's Solaris OS to perform a similar task, and later modified it for Apple's Mac OS-es. In 2012 I converted the script to use Apple's "caffeinate" utility. I believe that this script will execute most any other shell script that you'd like to run while preventing sleep mode from happening. It performs this task by executing the shell script whose name you include on the command line as an argument to the "caffeinated-script.sh" script, then it determines the PID of the process associated with this execution and "caffeinate"s that process. When the shell script completes its execution, the caffeinate process terminates allowing for the computer to then go to sleep after the execution of the shell script. I find this useful for running long numerical computations or building code or LaTeX-ing large documents.

You would use this script at a Terminal prompt by the following:

. caffeinate-script.sh <name of shell script to execute and caffeinate>

Because the MacRumors "Attach files" button does not allow shell scripts to be attached, I renamed the shell script to "caffeinate-script.sh.txt" in order to attach it. You will need to rename it back to "caffeinate-script.sh" and change the permissions to 755, that is, at a Terminal prompt:

mv caffeinate-script.sh.txt caffeinate-script.sh
chmod 755 caffeinate-script.sh

You will also need to change the permissions to 755 on the shell script that you'd like to caffeinate:

chmod 755 <name of shell script to execute and caffeinate>

If you have any questions, or if the script doesn't work for you, let me know.

Solouki

Attachment: caffeinate-script.sh.txt
-------------------------------------------------------------------------------

Hummm...the "Attach files" button did not work for me. I tried to attached a regular ASCII text file with an extension of .txt but this did not work. Maybe you could help me? (I have done this before --- but probably over a year ago.)

I also tried "cut-and-paste"-ing the shell script into this post, but when I went to post it, it came back with an "Oops..." error saying that an error was encountered.
Thanks. I‘m a regular terminal user and could’ve written a similar script but curious to see yours and also probably would be too lazy to get it done, haha. Instructions not needed for me but hopefully helpful to others reading along.
Hummm...the "Attach files" button did not work for me. I tried to attached a regular ASCII text file with an extension of .txt but this did not work. Maybe you could help me? (I have done this before --- but probably over a year ago.)

I also tried "cut-and-paste"-ing the shell script into this post, but when I went to post it, it came back with an "Oops..." error saying that an error was encountered.

could try pasting it in with the code tags or compressing to zip. Dragging Also sometimes inexplicably works on here when the attach button doesn’t. If all else fails a shared iCloud, Dropbox or google drive link works if it’s worth the bother for you :)
 
Hello,

I'm considering buying a 13 inch macbook pro and use a large external display with it. I would also like to turn off the macbook pro`s display but use its keyboard. I can do this easily on Windows: I simply select to project the image on "second screen only" and bam: the laptop display is off, but I use its keyboard.

Is this possible on the mac? From what I've seen on other website, it's either a terminal command or magnet trick, which I'm not very interested in. Maybe a plugin?

Thanks
 
could try pasting it in with the code tags or compressing to zip. Dragging Also sometimes inexplicably works on here when the attach button doesn’t. If all else fails a shared iCloud, Dropbox or google drive link works if it’s worth the bother for you

Code:
#!/bin/bash

#
# Shell script:                caffeinate-script.sh
# Author:                     Solouki Barbican
# Purpose:                To stop sleep/hibernate mode while another script is executing.
# Usage:                . caffeinate-script.sh <filename-of-script-to-caffeinate.sh>
# Creation Date:             2001.05.12
# Modification Date:            2005.09.01
# Modification Date:            2012.12.03 (major revision, converted to caffeinate utility)
#
#
#################################################################################
# The folloing describes an example usage:
#
# This script may be used to build all of M4M including up-to-date
#  Tables of Contents, Table of Figures, Table of Tables, Indices,
#  and Bibliographies.  Since this build takes roughly 2-3 hours
#  (depending on the speed of the CPU), the Mac computer is
#  `caffeinated' so that it doesn't go into Sleep Mode in the middle
#  of a build.
#
# This bash script should be executed by the following commands (for example)
#  to build all of M4M:
#   . caffeinate_script.sh build_Scripts_M4M_all_copy_aux.sh
#  or, for example, to build just a single Thinking Problem:
#   . caffeinate_script.sh M4M-CM-Schulers-Pendulum-Thinking-Problem.sh
#
#  If the script returns to Terminal input, and if %1 job is stopped, then
#   enter "%1" to get the job running again and hit "RETURN" to restart
#   the caffeinate script.
#
#  You should probably set GPG_wait_for_input="YES" in your input script so that
#   the build will wait for you to return to enter the GPG passphrase instead of
#   just timing out.  After stopping the first time, you can enter "NO" in order
#   that the build-box.sh script does not stop for future GPG passphrases (I have
#   set my GPG Suite remember passphrase time to 1200 or 3600 seconds instead of
#   the default 600 seconds).
#
# When the script finishes (returns to Terminal prompt), the M4M build is complete.
#################################################################################

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Arguments to the caffeinate-script.sh script:
CAFF_arguments="$@"
CAFF_arguments_upper=`echo $CAFF_arguments | tr '[:lower:]' '[:upper:]'`
##CAFF_argument_1=`echo $CAFF_arguments | awk '{print $1}' | tr '[:lower:]' '[:upper:]'`
CAFF_argument_1=`echo $CAFF_arguments | awk '{print $1}'`
##CAFF_argument_2=`echo $CAFF_arguments | awk '{print $2}' | tr '[:lower:]' '[:upper:]'`
CAFF_argument_2=`echo $CAFF_arguments | awk '{print $2}'`
CAFF_argument_3=`echo $CAFF_arguments | awk '{print $3}' | tr '[:lower:]' '[:upper:]'`
CAFF_argument_4=`echo $CAFF_arguments | awk '{print $4}' | tr '[:lower:]' '[:upper:]'`
CAFF_argument_5=`echo $CAFF_arguments | awk '{print $5}' | tr '[:lower:]' '[:upper:]'`
CAFF_script=${CAFF_argument_1}
#CAFF_test="YES"
CAFF_test="No"
if [ ! \( "$CAFF_test" = "No" \) ]; then
echo "      Number of args = $#"
echo "       CAFF_arguments = $CAFF_arguments"
echo " CAFF_arguments_upper = $CAFF_arguments_upper"
echo "      CAFF_argument_1 = $CAFF_argument_1"
echo "      CAFF_argument_2 = $CAFF_argument_2"
echo "      CAFF_argument_3 = $CAFF_argument_3"
echo "      CAFF_argument_4 = $CAFF_argument_4"
echo "      CAFF_argument_5 = $CAFF_argument_5"
echo "          CAFF_script = $CAFF_script"
if [ \( "$CAFF_test" = "YES" \) ]; then
     # If CAFF_test=YES, then:
     echo " After reading arguments to caffeinate-scrupt.sh: "
     read -p " [Hit <return> to continue, NO to end stopping, CONT to continue stopping, EXIT to exit]: " INPUTTEMP
     INPUTTEMP=`echo $INPUTTEMP | tr '[:lower:]' '[:upper:]'`
     if [ "$INPUTTEMP" = "NO" ]; then
     CAFF_test="No"
     fi # if [ "$INPUTTEMP" = "NO" ]; then
     if [ "$INPUTTEMP" = "CONT" ]; then
     CAFF_test="YES"
     fi # fi of if [ "$INPUTTEMP" = "CONT" ]; then
     if [ "$INPUTTEMP" = "EXIT" ]; then
###     cd ${BashDirectory_caffeinate}
     return
     exit
     fi # if [ "$INPUTTEMP" = "EXIT" ]; then
fi # if [ \( "$CAFF_test" = "YES" \) ]; then
fi # fi of if [ ! \( "$CAFF_test" = "No" \) ]; then
# ----------------------------------------------------------------------

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# List the shell variables and global environment variables:
#( set -o posix ; set ) | grep -i gpg            # for bash
#( set -o posix ; set ) | grep -i bash            # for bash
###( setopt posixbuiltin; set; ) | grep -i gpg        # for zsh
###( setopt posixbuiltin; set; ) | grep -i bash        # for zsh
unset BashDirectory_caffeinate
unset BashScript_caffeinate
unset BashTarget_caffeinate
unset CurrentDirectory_caffeinate
# ----------------------------------------------------------------------

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Determine which caffeinate-script.sh is being executed:
CurrentDirectory_caffeinate="$( cd -P "$( dirname "." )" && pwd )"
BashScript_caffeinate="${BASH_SOURCE[0]}"
while [ -h "$BashScript_caffeinate" ]; do # Resolve $BashScript until it is no longer a symlink
  BashTarget_caffeinate="$(readlink "$BashScript_caffeinate")"
  if [[ $BashScript_caffeinate == /* ]]; then
    echo " Bash Script: '$BashScript_caffeinate' is an Absolute Symlink to: '$BashTarget_caffeinate'"
    BashScript_caffeinate="$BashTarget_caffeinate"
  else
    BashDirectory_caffeinate="$( dirname "$BashScript_caffeinate" )"
    echo " Bash Script: '$BashScript_caffeinate' is a Relative Symlink to: '$BashTarget_caffeinate' (relative to '$BashDirectory_caffeinate')"
    BashScript_caffeinate="$BashDirectory_caffeinate/$BashTarget_caffeinate" # If $BashScript was a relative symlink, resolve it relative
                            #   to the path where the symlink file was located
  fi
done
RBashDirectory_caffeinate="$( dirname "$BashScript_caffeinate" )"
BashDirectory_caffeinate="$( cd -P "$( dirname "$BashScript_caffeinate" )" && pwd )"
if [ "$BashDirectory_caffeinate" != "$RBashDirectory_caffeinate" ]; then
  echo "  Directory: '$RBashDirectory_caffeinate' resolves to: '$BashDirectory_caffeinate'"
fi
echo " "
echo "      Bash Script's Name: '$BashScript_caffeinate'"
echo " Bash Script's Directory: '$BashDirectory_caffeinate'"
echo "       Current Directory: '$CurrentDirectory_caffeinate'"
echo " "
# ----------------------------------------------------------------------

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Configure the variables for building M4M:
M4M_dir="${HOME}/Math"
##export M4M_dir
#echo $PWD
if [ -f math_build.login ]; then
    #echo " Conditional: if [ -f math_build.login ]"
    . math_build.login
else
    #echo " Conditional: if [ -f math_build.login ] else"
    if [ -f $M4M_dir/Scripts/math_build.login ]; then
    . $M4M_dir/Scripts/math_build.login
    fi # fi of if [ -f $M4M_dir/Scripts/math_build.login ]; then
fi
#echo $PWD
# --------------------------------------------------------------------------------

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Execute the script:
#  There are several alterantive ways to execute the script, pick one
#   (uncomment the way particular commands below that you wish to use).
cd $CurrentDirectory_caffeinate
echo " ******************************************************************************** "
echo " PWD = ${PWD}"
echo "  Script to caffeinate:"
#echo "   ./${CAFF_script} >>/dev/null 2>&1 & "
#./${CAFF_script} >>/dev/null 2>&1 &
echo "   ./${CAFF_script} & "
./${CAFF_script} &
#echo "   . ${CAFF_script} &"
#. ${CAFF_script} &
#echo "   source ${CAFF_script} &"
#source ${CAFF_script} &
echo " ******************************************************************************** "
# --------------------------------------------------------------------------------

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Caffeinate the script:
sleep 5
#  Find the script's process ID:
caffpid=`ps auxww | grep -i ${CAFF_script} | grep -v grep | awk -F ' ' '{print $2}'`
export caffpid
echo "   Following is the caffeinated script:"
ps auxww | grep -i ${CAFF_script} | grep -v grep | awk -F ' ' '{print $2}'
echo "   PID of the caffeinated script: ${caffpid}"
# Caffeinate the process:
caffeinate -ims -w ${caffpid} &
sleep 5
echo "   Following is the caffeinate process:"
ps auxww | grep -i caffeinate | grep -v grep | awk -F ' ' '{print $2}'
#  After the caffeinated process complete, the caffeinate halts.
# --------------------------------------------------------------------------------

Okay ... even though the Preview gave me an "Oops..." error, I went ahead and "Post reply"-ed the CODE section and it worked.

Hope this is helpful...

Solouki
 
Last edited:
Your script-writing is soooo much more detailed and descriptive than mine, haha. Especially with comments. Nicely don, mate. And thanks

Let me know if you find the caffeinated-script.sh shell script useful...I personally use it all the time.
 
Don’t have a 16”, but if the brightness slider is the same you could always just set brightness to 0 which should turn off the display panel, while keeping the computer going. Alternatively check if the Hot Corner option for display sleep is purely display sleep or that also stops the downloads

Technically, brightness slider at 0 does not turn panel off, at least didn't back in days when you had the glowing apple logo. You could shine torch through the logo and see that display was still on, it was literally onlt the backlight turned off.
 
  • Like
Reactions: me55
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.