Hi, Here's how i do it using launchctl on OSX. Works a treat, no ugly icons or anything. It launches on startup, and keeps re-trying to launch until it succeeds in connecting to PMS, so it doesn't matter if it manages to start before PMS.
First, we need to make it quit if it manages to start before PMS, so launchctl can retry in 10s. Open up PlexGDM.py and search for the line 'No servers discovered'. Insert a line below this, at the same indentation, and add: sys.exit(1)
Next, we need to make it work without any access to the keyboard. Open up PlexConnect.py, look for the line that says 'try:', and delete this line *and every other line after it*. Don't worry, all you're removing is the ability for it to cleanly shut down if the user presses a key.
I followed your instructions. But when i enter the command sudo launchctl start com.plex.plexconnect i get an error stating: launchctl start error: Bad file descriptor
What am i doing wrong?
When i go back and do this command again: sudo launchctl load /Library/LaunchDaemons/com.plex.plexconnect.plist it says: com.plex.plexconnect: Already loaded
I followed you guide to make PlexConnect automatically start. However, does this mean that the AppleScript Icon will always be in the dock? is there a way to make this work in the background without adding any extra icons?
I also tried running the script with Platypus but my Apple TV does not respond if I use Platypus. Did I do it right?
Edit: Nevermind, I totally forgot to add the filed bundled into the script.
Any idea why your launchctl script fails to launch the correct and newer version of Python when PlexConnect.py uses ‘/usr/bin/env python’ instead of ‘/usr/bin/python’? Specifically, I have Python 2.6.1 as the system default Python installed on my system. But this version has problems with PlexConnect, so I installed Python 2.7.5. If I use an absolute path in PlexConnect.py to the new the newer Python (#!/usr/local/bin/python), your launchctl script works perfectly. But if I use the recommended shebang (#!/usr/bin/env python), the launchctl script launches the older version of Python. If I launch the PlexConnect.py script manually, it uses the newer version as it should.
Over in this thread, institute11 posted something he found that might point to the cause of and solution to (if there is one) the problem with running a python script at startup if it uses ‘/usr/bin/env python’:
This is from a python.org mail thread. Maybe it explains why it doesn’t work with launchctl.
One of the main dis-advantages to using ‘/usr/bin/env python’ is that
you have to either A. make sure the environment is initialized, or B.
initialize the environment manually before executing the script. If
you, for example, want to use a python script at boot time, before the
environment is initialized, i strongly recommend using an absolute path.
I installed the latest version of plexconnect which changed the path to use /usr/bin/env python but I still get the error 1 when trying to load the plex connect.plist
2013-06-20 21:17:26,135 com.apple.launchd[1]: (com.plex.plexconnect[10870]) Exited with code: 1
Running stand alone is no problem though.
Edit: Changed the path from /usr/dev/env python to what it actually is which is /usr/bin/env python
Did you edit the file to “/usr/dev/env python”? Because I think that should actually be “/usr/bin/env python”.
I installed the latest version of plexconnect which changed the path to use /usr/dev/env python but I still get the error 1 when trying to load the plex connect.plist
2013-06-20 21:17:26,135 com.apple.launchd[1]: (com.plex.plexconnect[10870]) Exited with code: 1
If I run this command in Terminal /usr/bin/env python it opens Python version 2.7.2 which should be ok with PlexConnect. That is also what I see in the PlexConnect.py file. BTW in previous post that was a mistake on my part. It actually says /usr/bin/env python.
For some reason the launchd plist provided above doesn’t work with “/usr/bin/env python” so you’ll have to edit the first line of PlexConnect.py with the absolute path of your Python install, either “/usr/bin/python” or “/usr/local/bin/python”. In your case, it should be “/usr/bin/python”.
If I run this command in Terminal /usr/bin/env python it opens Python version 2.7.2 which should be ok with PlexConnect. That is also what I see in the PlexConnect.py file. BTW in previous post that was a mistake on my part. It actually says /usr/bin/env python.
Sadly, it appears that chulbert1234's launchctl script will ignore any user set PATH variables when using "#!/usr/bin/env python" in PlexConnect.py. It seems that launchctl doesn't look beyond "PATH="/usr/bin:/bin:/usr/sbin:/sbin". So, if you have a newer version of Python installed in "/usr/local/bin", chulbert1234's launchctl plist will ignore that path and use OS X's default Python install at "/usr/bin".
Now this isn't too big of a deal for Lion and Mountain Lion users because they have Python 2.7 installed by default, but for those of use still on Snow Leopard, it means that we'll see the annoying graphical metadata glitches (i.e., "((ERROR:VAL))") when viewing video info about actors, directors, and producers in PlexConnect.
The only way around this launchctl restriction that I can find is to edit the PlexConnect files to use absolute paths to any newer user-installed Python (e.g., /usr/local/bin/python) in the shebang line that starts each PlexConnect file. It's inconvenient, but if you use Search-and-Replace in TextWrangler or BBedit, it's not too bad.
Sadly, it appears that chulbert1234's launchctl script will ignore any user set PATH variables when using "#!/usr/bin/env python" in PlexConnect.py. It seems that launchctl doesn't look beyond "PATH="/usr/bin:/bin:/usr/sbin:/sbin". So, if you have a newer version of Python installed in "/usr/local/bin", chulbert1234's launchctl plist will ignore that path and use OS X's default Python install at "/usr/bin".
Now this isn't too big of a deal for Lion and Mountain Lion users because they have Python 2.7 installed by default, but for those of use still on Snow Leopard, it means that we'll see the annoying graphical metadata glitches (i.e., "((ERROR:VAL))") when viewing video info about actors, directors, and producers in PlexConnect.
The only way around this launchctl restriction that I can find is to edit the PlexConnect files to use absolute paths to any newer user-installed Python (e.g., /usr/local/bin/python) in the shebang line that starts each PlexConnect file. It's inconvenient, but if you use Search-and-Replace in TextWrangler or BBedit, it's not too bad.
You could try a technique called chain loading to load the PlexConnect script at boot time with an extended environment i.e. you get launchtl to call a standard shell script which in turn sets the environment up correctly and then calls the PlexConnect script.
Hi, Here's how i do it using launchctl on OSX. Works a treat, no ugly icons or anything. It launches on startup, and keeps re-trying to launch until it succeeds in connecting to PMS, so it doesn't matter if it manages to start before PMS.
First, we need to make it quit if it manages to start before PMS, so launchctl can retry in 10s. Open up PlexGDM.py and search for the line 'No servers discovered'. Insert a line below this, at the same indentation, and add: sys.exit(1)
Next, we need to make it work without any access to the keyboard. Open up PlexConnect.py, look for the line that says 'try:', and delete this line *and every other line after it*. Don't worry, all you're removing is the ability for it to cleanly shut down if the user presses a key.