i have the latest plex server up and running on my mac mini (late 09, 10.9.2). everything works fine. the mac mini is usually in sleep mode. when i am at home, my logitech harmony wakes the system directly into plex home theater. so far so good.
for the scenario that i am not at home but i want to stream a movie to my iphone/notebook i have set up wake-on-lan on my mac mini. this actually works! even wake-over-internet works great. but there is a crucial issue: after exactly 1 minute the mac mini goes back into sleep mode. this even happens if i have already started a stream. the stream stops, the library goes offline and the mac mini is back in sleep mode.
i have been told that this is a normal behaviour. after the mac mini receives a wake-on-lan package, it wakes up and listens to services such as SSH or remote login. if there is no response the mac goes back into sleep mode.
my suggestion or better said, request: the plex server should keep the mac awake as soon as a connection has been established.
or is there any other nice way to keep the make awake after a wake-on-lan attempt?
This solution no longer works in El Capitan because com.apple.Boot.plist cannot be changed.
I found a solution that allows my Mac Mini to sleep normally, unless my Plex server is being accessed. It works by putting Plex in debug logging mode, and then checking the Plex log file every 30 seconds to see if it has changed. If so, it assumes someone is accessing Plex so it runs caffeinate to prevent the Mac from sleeping for 5 minutes.
Note that if the Plex server is not being accessed, then no new log messages will be written to the Plex logs, so caffeinate will not be run, so your Mac will sleep as normal!
Create ~/Library/LaunchAgents/PlexCaffeinate.plist as follows:
Does it work with 10.11.6?
I’m completly newby in such things. For example you write “create” - with what App/Programm? Could you do step by step for dummies?
Here’s a step-by-step guide. The main issue is that directory ~/Library is hidden by default in Mac OS X, so is not easy to access from Finder. So you’ll run all these commands from Terminal.
From the Dock, run Launchpad > Other > Terminal
In the Terminal window that pops up, copy-paste the following (and hit return):
echo "" >> ~/Library/LaunchAgents/PlexCaffeinate.plist && open -a TextEdit ~/Library/LaunchAgents/PlexCaffeinate.plist
In the empty TextEdit window that pops up, copy-paste the text from the box in item (1) in my earlier post above.
In the TextEdit menu bar, click File > Save, then File > Close
Go back to the Terminal window, and copy-paste the following (and hit return):
Now leave that Terminal window open, and try accessing Plex and browsing your library (e.g. using your TV’s Plex app, or another computer). Once you’ve done that, go back to the Terminal window, and you should see the following message (after about 30 seconds):
Fri Sep 2 09:43:57 CEST 2016 Caffeinate...
After 5 minutes, the following message should appear in the Terminal window:
Fri Sep 2 09:48:56 CEST 2016 Caffeinated.
You can now safely quit Terminal (ignore any warnings it gives you). This PlexCaffeinate script will continue running in the background (and will be automatically started when you first login to your Mac).
You can still edit com.apple.Boot.plist, but it requires turning off SIP. I don’t know though after editing the file if you can re enable SIP and keep the changes.
My solution has the benefit that there’s no need to disable your Mac’s default power saving features (i.e. darkwake). It does have the following issues, but they’re relatively minor and overall it’s working great for me:
My Plex logs are now larger (but only a few Mb, and they’re automatically discarded)
Since Plex does periodic housekeeping causing the logs to get updated, my Mac sometimes gets kept awake for 5 minutes by my Caffeinate script when I’m not using Plex.
It would be great if Plex had an access log that only got updated when someone browsed the library. Then my script could monitor this for changes, instead of the debug log (solving both issues above).
@Parnty
Thx you for your guide!!! Will try it soon.
One more question - how can it be reverted / deleted if it does not work?
Are there any problems with future OSX or Plex updates?
The solution I’ve given should be compatible with all current and future versions of OS X, as it uses pretty fundamental Mac features that are unlikely to change. The only issue I can see is if Plex changes the name/location of their log files in a future release.
Then again, it would be even better if the Plex team would (continue their great work and) build a solution into Plex itself for preventing the Mac from sleeping while a user is browsing their Plex library. Fingers crossed!
If this works and my iMac could sleep while not in use with PMS and sleeps again after using it, the energysaving would be great. I have tried wimoweh as well. Doesnt work.
So, thanks to your step by step info even i could do it and it works flawless. Saves energy and money. You are my hero!! Many thanks.
Please keep it up to date if any changes in OSX OR PMS show up. Im a happy man.
@Plex
Please implement this in OSX PMS. It works and saves money.
Thanks for the script… but it kinda works for me…after it activates it doesn’t stop automatically after i close plex. and my mac is not going to sleep after that, even when i try to put in manually to sleep , i have to stop the caffeine process in activity monitor.
Help would be appreciated
thanks
works for me. works like it should. did exact the step by step guide. im on sierra and works. 5 min after last plex activity + after 10 min sleep in energy settings than my iMac sleeps like a baby. try to contact parnty
It’s possible your Plex server is doing housekeeping tasks in the background, and therefore writing messages to its log file. In this case, my script will assume someone is using Plex, so will run caffeinate to prevent your Mac from sleeping. Check this as follows:
From the Dock, click Launchpad > Other > Console
In the Console application, on the left-hand side click the triangle to expand ~/Library/Logs then Plex Media Server then click on Plex Media Server.log (make sure you click the file with this exact name)
If you see new messages continuously appearing in the right-hand pane, then this is the cause of the problem.
Your Plex Server may be doing a one-off (but long-running) housekeeping task. Once this has finished, your Mac will be able to sleep again. So you could just wait for a day or so.
You should also make sure your Plex Server is updated to the latest version.