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

jangozo

macrumors member
Original poster
Oct 10, 2012
35
0
Hi,

I stream via DLNA movies from my external hard drive but every time my mac reaches the set sleeping time, it shuts down. Is there a way to prevent my mac from sleeping whenever it's reading from the external hard drive? It would be better if it can monitor just whenever it's streaming but that would depend on the software I think.

Thanks.
 

jangozo

macrumors member
Original poster
Oct 10, 2012
35
0
Since there are so many views but no replies. I'll post the answer.

Option 1:
Crontab this script (the IP is the IP of my tv on dlna):
Code:
#!/bin/sh

script_name=`basename $0`
echo $script_name
coffee_time=20
if [ `ps -ef | grep -v grep | grep $script_name | wc -l` -eq 2 ]; then
	echo `date` "$script_name is checking for streams"
	until [[ -z `/usr/sbin/lsof -i @192.168.1.100` ]]; do
		echo `date` "Stream found. Caffeinating.." 
		caffeinate -t $coffee_time
	done
else
	echo `date` "$script_name is already running"
fi

Option 1:
Use sleepwatcher app and this script:
Code:
#!/bin/sh

coffee_time=20
until [[ -z `/usr/sbin/lsof -i @192.168.1.100` ]]; do
	echo `date` "Stream found. Caffeinating.." 
	caffeinate -t $coffee_time
done
 

GGJstudios

macrumors Westmere
May 16, 2008
44,556
950
Caffeine will temporarily override your energy saver settings and keep your Mac awake with a click on the Menu Bar icon. Another click turns it off.

To keep your Mac notebook awake with the lid closed, use InsomniaX or InsomniaT (rebuild for SL) (fix for 2011 MPBs)

NoSleep also keeps your Mac notebook awake when you close the lid.
 

jangozo

macrumors member
Original poster
Oct 10, 2012
35
0
Caffeine will temporarily override your energy saver settings and keep your Mac awake with a click on the Menu Bar icon. Another click turns it off.

To keep your Mac notebook awake with the lid closed, use InsomniaX or InsomniaT (rebuild for SL) (fix for 2011 MPBs)

NoSleep also keeps your Mac notebook awake when you close the lid.

All good apps but not what I'm after. They all require user input to stop the sleep when I'm streaming to my tv. There are times when I will forget it and there will be some swearing.
 

GGJstudios

macrumors Westmere
May 16, 2008
44,556
950
All good apps but not what I'm after. They all require user input to stop the sleep when I'm streaming to my tv. There are times when I will forget it and there will be some swearing.
You can set Caffeine to automatically launch when you start your Mac. No user input required.
 

jangozo

macrumors member
Original poster
Oct 10, 2012
35
0
You can set Caffeine to automatically launch when you start your Mac. No user input required.

Sure, it will automatically launch and prevent it from sleeping. This means there will be user input when I want it to go to sleep after some idle time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.