Can a Plex script execute "shell commands" ?

I see Plex as being more than just my media server. It’s my digital home interface. I currently have some home automation technology implemented and would like to write a script that controls some of the home devices (on/off etc).



I can trigger these events by executing a shell command from Mac OS Terminal. What I want to do is write a Plex script which comprises a tiered menu and which executes ‘Unix’ shell commands when a menu entry is selected.



Example :



Room 1



— Ceiling light

— Ceiling fan



Room 2

— Ceiling light

— Airconditioner



So far all the code examples focuses on media scraping. Is what I am thinking of possible ? Any pointers in the right direction would be most appreciated.



Thanks in advance

python has several different methods built in for doing exactly this, you can also capture stdio with your python script. there’s more than a couple methods for spawning a shell process, with varying uses and degrees of control and error handling. heres some references:



http://docs.python.org/library/subprocess.html



the recommended method seems to be to use the Popen class of the subprocess module, see the link above, it provides easy access to stdio and much much more. os.system(‘cmd’) and several other methods all seem to be depreciated in favor of the subprocess module

Although you could get it to work, we can’t guarantee compatibility with future versions if you make use of any Python functions or libraries outside of the provided framework. We’ll be changing the architecture the plug-in system considerably over the next few months, and are aiming to sandbox them to prevent access to the entire system (which could become a pretty big security problem if anyone ever chose to abuse it). Plug-ins which only use the framework will be unaffected, but any unsupported code may behave strangely or break completely.



What kind of “shell commands” are you wanting to run? There’s limited support for executing external helper programs bundled inside the plug-in.

The home automation system is controlled by a command line app called groupswrite. I just need the script to trigger groupswrite with some paratmeters.

the subprocess module is included with a standard python install, however if you do need to use a nonstandard python library, you can include the library inside your plugin bundle, i’ve seen a couple plugins that do that, i dont think future versions of plex will break your plugin, just future versions of the framework, as long as your plugin targets framework v1 it shouldn’t be affected i think.



out of curiosity jam, what’s the framework function for spawning a sub-process? and is it just a wrapper for Popen or os.system ?

Helper.Run(programname, arg1, arg2, etc.) will execute the named program inside the bundle in Contents/Helpers with the given arguments, and return any output. A more comprehensive method of spawning & redirecting IO is planned for a future update.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.