Has anyone created an AppleScript/Application to launch PlexConnect at startup?

It is probably running. To check in terminal run the same sudo command by replace “start” with “status” (you can also replace it with “stop”).

It is probably running. To check in terminal run the same sudo command by replace "start" with "status" (you can also replace it with "stop").

It is definitely running.  I installed the certificate and can access trailers fine.  Just can't get the applescript to work.  Is there no way to generate a console log?

After a lot of tweaking i have PlexConnect auto starting on my Maverick MacMini, and everything has bee running smoth for a few days. I would like to benefit from all the improvements being made to PlexConnect, but do not dare to risk messing up my system.

Is it “fail safe” to update with the new distribution from github?

Is the Autostart sw as described above included in the github distributions?

What needs to be tweaked in the github distributions to ensure that auto start is not lost?

Is there a way to create shortcuts to the status and stop terminal commands so i can stop PlexConnect fast to update?

I have discovered some new information on trying to implement PlexConnect with the applescript on Mavericks.  If I run the script in the script editor, I get "Plexconnect starting ..."  If I check the status in terminal and look on my appletv, it is indeed running.  If I run my PlexConnect.app, PlexConnect starts and immediately stops.

14:28:25 PlexConnect: started: 14:28:25
14:28:25 PlexConnect: IP_self: 192.168.1.208
14:28:25 DNSServer: started: 14:28:25
14:28:25 DNSServer: ***
14:28:25 DNSServer: DNSServer: Serving DNS on 192.168.1.208 port 53.
14:28:25 DNSServer: ***
14:28:25 WebServer: started: 14:28:25
14:28:25 WebServer: ***
14:28:25 WebServer: WebServer: Serving HTTP on 192.168.1.208 port 80.
14:28:25 WebServer: ***
14:28:25 PlexConnect: Shutting down.
14:28:25 PlexConnect: Shutting down.
14:28:26 WebServer: Shutting down.
14:28:30 DNSServer: Shutting down.
14:28:30 PlexConnect: shutdown
 
So the problem lies in the process of exporting to an app from the applescript editor.  This is really no big deal, but I have more time than I would like to admit in the process.

I have discovered some new information on trying to implement PlexConnect with the applescript on Mavericks.  If I run the script in the script editor, I get "Plexconnect starting ..."  If I check the status in terminal and look on my appletv, it is indeed running.  If I run my PlexConnect.app, PlexConnect starts and immediately stops.

14:28:25 PlexConnect: started: 14:28:25
14:28:25 PlexConnect: IP_self: 192.168.1.208
14:28:25 DNSServer: started: 14:28:25
14:28:25 DNSServer: ***
14:28:25 DNSServer: DNSServer: Serving DNS on 192.168.1.208 port 53.
14:28:25 DNSServer: ***
14:28:25 WebServer: started: 14:28:25
14:28:25 WebServer: ***
14:28:25 WebServer: WebServer: Serving HTTP on 192.168.1.208 port 80.
14:28:25 WebServer: ***
14:28:25 PlexConnect: Shutting down.
14:28:25 PlexConnect: Shutting down.
14:28:26 WebServer: Shutting down.
14:28:30 DNSServer: Shutting down.
14:28:30 PlexConnect: shutdown
 
So the problem lies in the process of exporting to an app from the applescript editor.  This is really no big deal, but I have more time than I would like to admit in the process.

Nevermind, I figured it out.  Dummy misstake, I didn't have "stay open after run handler" checked.  It's usually something simple.  Thanks all for help.

Nevermind, I figured it out.  Dummy misstake, I didn't have "stay open after run handler" checked.  It's usually something simple.  Thanks all for help.

 Yep, came to tell you it's probably it :)

If you make the script in the methods that matches to Mavericks everything is still fine :)

1

1

?

?

PlexConnect.app v.1.0

http://forums.plexapp.com/index.php/topic/85156-plexconnectapp/

Well I'm at my wits end. Have PlexConnect set up and running on Mavericks. I can start it with terminal commands either directly calling PlexConnect.py or the PlexConnect_daemon.bash in my PlexConnect folder. However when I try the modified AppleScript for Mavericks I get the following error message "/bin/sh: Applications/PlexConnect/PlexConnect_daemon.bashstart: no such file or directory". I'm a newbie at running PlexConnect and AppleScripts so I feel there must be something simple I'm missing. Hoping to surprise my wife with the Apple TV and I need to automate this the improve the acceptance factor. Thanks for any help.

Well all I had to do was post this and I found error, missing space before " start" in PlexConnect_daemon.bash Mavericks modifications. All is well now.

You can wait for his app or give my methods a try till he releases the new version:

http://forums.plexapp.com/index.php/topic/84307-launchctl-and-applescript-methods-for-plexconnect-on-mavericks-osx/

I took a look at the script and did some more digging and found out that the reason for the password on quit had to do with variable scoping in AppleScript.

Below is updated code that should:

  1. Kill all python threads associated with PlexConnect upon quitting
  2. Utilize all the data saved in the keychain item (not just password therefore it is much more generic)
  3. Use global variables for all the above to avoid any weird issues in the handlers

There are only three steps to setup this code to work:

  1. Change the "/path/to/PlexConnect.py" to your correct path on your file system (BTW Drag and Drop is your friend, you can drag and drop PlexConnect.py from whatever folder it is into AppleScript Editor and it will insert the absolute path to the file)
  2. Create a generic keychain entry with your admin name as the account name and admin password as the password.
  3. Save the AppleScript as Stay Open Application

The Updated Code:

global py
global un
global theKeychainItem
global thePassword
set py to "/path/to/PlexConnect.py"  //change me
set theKeychainItem to "Name of Keychain Item"  //change me
set un to getUsername(theKeychainItem)
set thePassword to getPassword(theKeychainItem)

do shell script "screen -A -m -d -S PlexConnect " & py user name un password thePassword with administrator privileges

on quit
do shell script “kill ps -u root | grep [P]lexConnect | grep [Pp]ython | awk '{print $2}'” user name un password thePassword with administrator privileges
continue quit
end quit

on getPassword(KeychainItem)
set theResult to do shell script "security 2>&1 find-generic-password -gs " & KeychainItem
set theResult to extractData(theResult, “password: "”, “"”, 0)
return theResult
end getPassword

on getUsername(KeychainItem)
set theResult to do shell script "security 2>&1 find-generic-password -gs " & KeychainItem
set theResult to extractData(theResult, “"acct"="”, “"”, 0)
return theResult
end getUsername

on extractData(theText, theFieldName, theEndDelimiter, spaces)
set theDataStart to the offset of theFieldName in theText
if theDataStart = 0 then
return “”
else
set theDataStart to theDataStart + (length of theFieldName) + spaces
set theData to text theDataStart through end of theText
set theDataEnd to ((offset of theEndDelimiter in theData) - 1)
set theData to text 1 through theDataEnd of theData
end if
end extractData

I see this as a very flexible solution especially if updating source regularly or bouncing between different branches.

Hope this helps.

Chris I have tried your code and I came up with error:

 
![post-225227-0-74477300-1394415578.png|460x500](upload://tTXwCRf249CHgCsQdec6iE1T0eD.png)
Any idea for the reason this is happening?

I don’t know why. I haven’t used this code in a while as I am currently running Plex Connect off of a raspberry pi. I would look in to the official daemon code that baa and the bunch have introduced in the last couple of months.

Chris I have tried your code and I came up with error:

 
Any idea for the reason this is happening?

I believe this broke in 10.9.x. I had stopped using the "screen" command in the applescript and switched to using the daemon bash script. However, in 10.9.2 apple broke that as well so now the applescript application will not shutdown gracefully. I have to force quit, which leaves the python running. I haven't found a workaround yet but submitted a bug report to apple. 

Once baa released the daemon now you can start plexconnect at boot by navigating to support/OSX then issuing this command via terminal:


sudo ./install.bash


This installs com.plex.plexconnect.bash.plist in /Library/LaunchDaemons and starts plexconnect at boot.


As an alternative you can use OpenConnect in my signature to automate this. It doesn’t require terminal at all to install plexconnect at boot.

I believe this broke in 10.9.x. I had stopped using the "screen" command in the applescript and switched to using the daemon bash script. However, in 10.9.2 apple broke that as well so now the applescript application will not shutdown gracefully. I have to force quit, which leaves the python running. I haven't found a workaround yet but submitted a bug report to apple. 

This Applescript is obsolete and you should not be using it any more, try using the official method for autostarting PlexConnect that is in place (make sure you are running recent code):

Once baa released the daemon now you can start plexconnect at boot by navigating to support/OSX then issuing this command via terminal:

sudo ./install.bash

This installs com.plex.plexconnect.bash.plist in /Library/LaunchDaemons and starts plexconnect at boot.

As an alternative you can use OpenConnect in my signature to automate this as it doesn't require terminal at all.

While that launch daemon will start PlexConnect, running launchctl unload does not stop it since it doesn't execute the PlexConnect_daemon.bash stop command. I like to be able to start and stop so i can upgrade the code at will.

I did find a "not so glamorous" solution. I edited my sudoers file to all only my username to execute PlexConnect_daemon.bash without typing a password. Then in my applescript (which is bundled in an application) i changed the code to call "sudo /Users/rob/Development/PlexConnect/PlexConnect_daemon.bash start/stop"

This Applescript is obsolete and you should not be using it any more, try using the official method for autostarting PlexConnect that is in place (make sure you are running recent code):

Are you sure about this statement:

  • sudo launchctl unload /Library/LaunchDaemons/com.plex.plexconnect.bash.plist will unload or stop the service for this boot.

If you unload the plist via launchctl it stops plexconnect. This is how my app was designed to work also.


You can check by looking at your system processes running python instances or typing in your plexconnect host ip into any browser on your network. If it says error response plexconnect is running. If not it is not.