How to keep System Events from deactivating

applescript

I'm using more and more Applescripts for home automation that rely on System Events being active. The problem is that System Events shuts down if it hasn't been used for a while. I'm not sure how long the time is though. 15 min? 5 min? Regardless… if System Events isn't active, there's either a pause or an error while it launches, meanwhile I wonder what happened. I don't want to build delays into the Applescripts because many of them are for remote control type actions (imagine if your TV required a 10 second delay every time you tried to use your remote. That'd be annoying).

Is there a way to keep System Events active? Is there a reason to NOT keep System Events active?

I'm on Mavericks, if that matters.

Best Answer

Save this plist as ~/Library/LaunchAgents/systemevents.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>systemevents</string>
  <key>Program</key>
  <string>/System/Library/CoreServices/System Events.app/Contents/MacOS/System Events</string>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>

Then run launchctl load ~/Library/LaunchAgents/systemevents.plist.

It doesn't fix the glitches in the QuickHue script though. I was probably wrong when I said that the error was caused by System Events not being open.