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

I just updated PlexConnect to the lastet zip from github and the app stopped working! By the terminal it's working great ..

I just updated PlexConnect to the lastet zip from github and the app stopped working! By the terminal it's working great ..

Are you on Mavericks or ML? Did you modify the applescript to use the daemon bash script? If so, when you downloaded the latest code from github you probably overwrote your changes to daemon script, specifically the INSTALL_DIR variable.

Are you on Mavericks or ML? Did you modify the applescript to use the daemon bash script? If so, when you downloaded the latest code from github you probably overwrote your changes to daemon script, specifically the INSTALL_DIR variable.


If you want to amalgamate and post the information for Mavericks step by step I will edit the first post to reflect it (it is a lot of pages for newbies to wade through).

If you want to amalgamate and post the information for Mavericks step by step I will edit the first post to reflect it (it is a lot of pages for newbies to wade through).

Yes please, that'd be ace!

Cheers

I know it is a lot of work guys but I tried it and it didnt work I am on mavericks and I am new to all this plex n terminal stuff but I follow instructions well. I have ATV3 and MBP everytime I start up I get a message asking me if I want to allow plex media server to accept incoming connections, I do not know how to permanently allow it....

and also I need to get the whole process automated... THANKS

You dont have to rename /applications/plex media server.app to pms.app if you dont want to it works either way as long as you change the plist accordingly to whatever name u like same goes for renaming the other portion to pms as well

1. Copy your plex app and rename it to PMS in /applications
2. Show package contents of your new app PMS and rename Applications/PMS.app/Contents/MacOS/Plex Media Server to PMS
3. Copy the com.plex.pms.plist to /library/lauchdaemons
4. Fire up terminal and sudo su enter password.
5. Change directory to /library/launchdaemons
6. Enter this in terminal: chown root:wheel com.plex.pms.plist
7. Then this: sudo launchctl load /Library/LaunchDaemons/com.plex.pms.plist
8. I also added this to plexconnect.py above (import sys, time) at the beginning of the file I dont know if its needed but I wanted to be sure PMS was up and running prior to PLEX CONNECT Launchctl plist: 

I have mavericks and I tried this but it did not work.... since I do not have launchdaemons I used launchagents followed the change of name etc coz i like the shorter name too.... but when I do the chown root thing. it says file not found

Ok i figured out how to fix this to work on Mavericks. By using the daemon script that has been added to the most recent version of PlexConnect, you can modify the applescript to use it instead of using the "screen" command. Here's the changes you need to make.

1. In PlexConnect_daemon.bash script, change the INSTALL_DIR variable to the fully path of your PlexConnect directory

INSTALL_DIR="/Users/rob/Development/PlexConnect"

2. In the applescript, change the "py" variable to point to the daemon script

set py to "/Users/rob/Development/PlexConnect/PlexConnect_daemon.bash"

3. In the applescript, change the "do shell" and "on quit" sections to pass the start and stop parameters to the daemon script. Take notice that there is a space before "start" and "stop"

do shell script py & " start" user name un password thePassword with administrator privileges

on quit
do shell script py & " stop" user name un password thePassword with administrator privileges
continue quit
end quit

Gents - getting back to this after a week of letting it run on the old terminal startup.

I made the above edits to my AppleScript app and the services all appear to be starting properly, but the app won't quit cleanly.

If I right click on it in my dock I only get "Force Quit" rather than "Quit" and if I force quit the python process don't exit cleanly so I have to force quit them from Activity monitor.

Not the biggest of worries since it is working and I can watch PMS content on my AppleTV, and I rarely reboot this computer, and it'll start in my log-in items, but an annoyance nonetheless to force quit each time I have to update to the newest PMS.

I did a git pull this morning (1 Nov 2013 - 10:00am CET) and should be on the latest & greatest code.

EDIT - after editing the AppleScript I compiled and saved it - do I need to re-export as an app?

Are you on Mavericks or ML? Did you modify the applescript to use the daemon bash script? If so, when you downloaded the latest code from github you probably overwrote your changes to daemon script, specifically the INSTALL_DIR variable.

Mavericks. Check the signature .. Anyway got it to work .. Probably something in keychain acess

@jdanielca you absolutely have lauchdaemons it is located at /library/launchdaemons. This is the proper place where you need to place your autostarting.plists. I have mavericks as well.

My updated guide for mavericks is here also:

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

The code you need to get the plist to work is within this guide:

http://forums.plexapp.com/index.php/topic/80703-plex-media-server-plexconnect-startup-scripts-for-osx/

All of these are in my signature below.

@jdanielca you absolutely have lauchdaemons it is located at /library/launchdaemons. This is the proper place where you need to place your autostarting.plists. I have mavericks as well.

My updated guide for mavericks is here also:

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

The code you need to get the plist to work is within this guide:

http://forums.plexapp.com/index.php/topic/80703-plex-media-server-plexconnect-startup-scripts-for-osx/

All of these are in my signature below.

I have launchagents not launch daemons... looks like it has plist stuff too but I dont have launch daemons thats for sure.

You can create the LaunchDaemons folder if it’s not there.

You can create the LaunchDaemons folder if it's not there.

are you telling me you have launch agents AND launch daemons?

Yes.

ok :)

Ok i figured out how to fix this to work on Mavericks. By using the daemon script that has been added to the most recent version of PlexConnect, you can modify the applescript to use it instead of using the "screen" command. Here's the changes you need to make.

1. In PlexConnect_daemon.bash script, change the INSTALL_DIR variable to the fully path of your PlexConnect directory

INSTALL_DIR="/Users/rob/Development/PlexConnect"

2. In the applescript, change the "py" variable to point to the daemon script

set py to "/Users/rob/Development/PlexConnect/PlexConnect_daemon.bash"

3. In the applescript, change the "do shell" and "on quit" sections to pass the start and stop parameters to the daemon script. Take notice that there is a space before "start" and "stop"

do shell script py & " start" user name un password thePassword with administrator privileges

on quit
do shell script py & " stop" user name un password thePassword with administrator privileges
continue quit
end quit

I have been working on this for several hours with little success.  I made the changes above.  When I run in the Applescript editor, I get "starting plexconnect ..." in results.  No python processes are showing up in activity monitor (not sure if there should be).  If I run the generated app, plexconnect shows up briefly in the dock and then disappears.  I had this running under ML, but no luck under Mavericks.  Any ideas?  I must be missing something simple, but am missing it.  Nothing shows up in console log.  How can I trouble shoot?

You cant try my mavericks applescript method if you like: http://forums.plexapp.com/index.php/topic/84307-launchctl-and-applescript-methods-for-plexconnect-on-mavericks-osx/

I have been working on this for several hours with little success.  I made the changes above.  When I run in the Applescript editor, I get "starting plexconnect ..." in results.  No python processes are showing up in activity monitor (not sure if there should be).  If I run the generated app, plexconnect shows up briefly in the dock and then disappears.  I had this running under ML, but no luck under Mavericks.  Any ideas?  I must be missing something simple, but am missing it.  Nothing shows up in console log.  How can I trouble shoot?

Can you post your full script so i can see what's wrong with it. Also, post your PlexConnect_daemon.bash.

global py
global un
global theKeychainItem
global thePassword
set py to "/Users/rob/Development/PlexConnect/PlexConnect_daemon.bash"
set theKeychainItem to "PlexConnect"
set un to getUsername(theKeychainItem)
set thePassword to getPassword(theKeychainItem)

do shell script py & " start" user name un password thePassword with administrator privileges

on quit
do shell script py & " stop" 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

Can you post your full script so i can see what's wrong with it. Also, post your PlexConnect_daemon.bash.

global py
global un
global theKeychainItem
global thePassword
set py to "/Users/rob/Development/PlexConnect/PlexConnect_daemon.bash"
set theKeychainItem to "PlexConnect"
set un to getUsername(theKeychainItem)
set thePassword to getPassword(theKeychainItem)

do shell script py & " start" user name un password thePassword with administrator privileges

on quit
do shell script py & " stop" 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

global py

global un

global theKeychainItem

global thePassword

set py to "/Users/peterream/Documents/PlexConnect-master/PlexConnect_daemon.bash"

set theKeychainItem to "PlexConnect"

set un to getUsername(theKeychainItem)

set thePassword to getPassword(theKeychainItem)

 

do shell script py & " start" user name un password thePassword with administrator privileges

 

on quit

do shell script py & " stop" 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

 

 

#!/bin/bash
 
#
# sample start stop script
#
 
# Package
DNAME="PlexConnect"
PNAME="PlexConnect_daemon"
 
# Others
INSTALL_DIR="/Users/peterream/Documents/PlexConnect-master"
PYTHON="python"
PROGRAM="${INSTALL_DIR}/${PNAME}.py"
PID_FILE="/var/${PNAME}.pid"
 
 
start_daemon ()
{
    cd "${INSTALL_DIR}"
    ${PYTHON} ${PROGRAM} --pidfile ${PID_FILE}
}
 
stop_daemon ()
{
    kill `cat ${PID_FILE}`
    wait_for_status 1 20 || kill -9 `cat ${PID_FILE}`
    rm -f ${PID_FILE}
}
 
daemon_status ()
{
    if [ -f ${PID_FILE} ] && kill -0 `cat ${PID_FILE}` > /dev/null 2>&1; then
        return
    fi
    rm -f ${PID_FILE}
    return 1
}
 
wait_for_status ()
{
    counter=$2
    while [ ${counter} -gt 0 ]; do
        daemon_status
        [ $? -eq $1 ] && return
        let counter=counter-1
        sleep 1
    done
    return 1
}
 
 
case $1 in
    start)
        if daemon_status; then
            echo ${DNAME} is already running
        else
            echo Starting ${DNAME} ...
            start_daemon
        fi
        ;;
    stop)
        if daemon_status; then
            echo Stopping ${DNAME} ...
            stop_daemon
        else
            echo ${DNAME} is not running
        fi
        ;;
    status)
        if daemon_status; then
            echo ${DNAME} is running
            exit 0
        else
            echo ${DNAME} is not running
            exit 1
        fi
        ;;
    *)
        exit 1
        ;;
esac

Everything looks in order. If you execute the following, does PMS start

sudo /Users/peterream/Documents/PlexConnect-master/PlexConnect_daemon.bash start

Everything looks in order. If you execute the following, does PMS start

sudo /Users/peterream/Documents/PlexConnect-master/PlexConnect_daemon.bash start

I get "starting plexconnect ..."   I don't know if Plex works on ATV as I have not addressed the cert fix yet.