Do you know what the Applescript Editor is? Cut and paste the script into an Applescript Editor window and save it as described in post #7.
Do you no what the Applescript Editor is? Cut and paste the script into an Applescript Editor window and save it as described in post #7.
thank you so much, i thought i should do it in platypus
i was confused, i'm trying and i'll update :)
thanks
thank you ! that's work !
I did allow "security" in those keychain settings, but this was added for me by default, because when you launch the AppleScript for the first time it, asks you to grant access. If you select "always allow," it does not ask for a password when you shut the app down. At least, that's my theory.
I've used this script and saved it as an application with a new icon. It works fine although when it quits it prompts for a password. The first time I ran this, it just started, it didn't prompt me to grant access. How do I get this to prompt for access so I can select "always allow"??
FYI, I'm just using the first script with the password entered in it, I'm not using the second script which utilises the keychain as its overkill for my needs.
I've used this script and saved it as an application with a new icon. It works fine although when it quits it prompts for a password. The first time I ran this, it just started, it didn't prompt me to grant access. How do I get this to prompt for access so I can select "always allow"??
FYI, I'm just using the first script with the password entered in it, I'm not using the second script which utilises the keychain as its overkill for my needs.
follow the first instruction in post #7 in this thread.
Just kidding. Totally works. My return statement was uncommented and therefore the script was exiting before the good bits.
Here is what I have so far with some explanation on how to get it working.
- Open keychain access and add a new entry with a unique item name and the password being your admin password. The account name is not used but you might as well enter your admin name for consistency.
- Paste the below into a new AppleScript document and save it as an Application and check the "Stay open after run handler" box
- Add it to your log in items
- Allow it access to your Keychain when asked
The only concern I have is that
securityis getting access to this item not the AppleScript app itself which means if you always allow it access to that item, someone could use the security command to lookup that one record which would make your admin password available.
Below is the currently functional script with Keychain Access integration:
set py to "path/to/PlexConnect.py" set un to "username" set theKeychainItem to "pw" #this is the name of the keychain item with your password in it #delay 10 #add this in or change the value as needed so that PlexConnect starts up after PMS set theResult to do shell script "security 2>&1 find-generic-password -gs " & theKeychainItem set thePassword to extractData(theResult, "password: \"", "\"", 0) do shell script "screen -A -m -d -S PlexConnect " & py user name un password thePassword with administrator privileges on quit do shell script "screen -A -m -d -S kill " & "kill `ps -u root | grep [P]lexConnect | grep python | awk '{print $2}'`" with administrator privileges continue quit end quit 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
hi
first of all, thank you so much, i did this and maked it seamless with dock dodger.
the only problem is that when i want to update plexconnect i am changing the files in the folder, and restarting the mac because i can't close the process, there is no live log like in the terminal on the normal plexconnect, so i can't click enter and make the process shutdown. if just qutting the app there's the leftover anyone is speaking about and after reopening it with the new files of course i'm having the port 80 in use error and must restart the computer.
if there will be a way to open the terminal windows when want to do things like shutdown (and close after that the terminal windows too..) it'll be so damm awesome.
thank you so much :)
You can kill the orphaned python processes by going into activity monitor and quitting all the python processes that you find. Still a pain, but better than rebooting the whole computer. I stopped using the script and reverted to terminal for this reason.
You can kill the orphaned python processes by going into activity monitor and quitting all the python processes that you find. Still a pain, but better than rebooting the whole computer. I stopped using the script and reverted to terminal for this reason.
for updating once a day the app is still better and going to activiy monitor still better.
thanks !
hi
first of all, thank you so much, i did this and maked it seamless with dock dodger.
the only problem is that when i want to update plexconnect i am changing the files in the folder, and restarting the mac because i can't close the process, there is no live log like in the terminal on the normal plexconnect, so i can't click enter and make the process shutdown. if just qutting the app there's the leftover anyone is speaking about and after reopening it with the new files of course i'm having the port 80 in use error and must restart the computer.
if there will be a way to open the terminal windows when want to do things like shutdown (and close after that the terminal windows too..) it'll be so damm awesome.
thank you so much :)
If you quit the AppleScript app, it will kill the python processes that's what this:
on quit
do shell script "screen -A -m -d -S kill " & "kill `ps -u root | grep [P]lexConnect | grep python | awk '{print $2}'`" with administrator privileges
continue quit
end quit
does.
If you are hiding the dock icon you're also removing the ability to easily quit the AppleScript app and thus defeating the above code block.
Hey! Thanks to all those involved in Plex Connect and this tweak around it. It really means a lot!
I've made the app with applescript but I really can't get it to work.
In my case, my item is named:plexappletv; adminpassword:11; item username:admin; macusername:Leand91.
So we should change the values for these three variables thats it?:
set py to "path/to/PlexConnect.py"
set un to "username"
set theKeychainItem to "pw"
And in my case that would be something like this?...
set py to "/Users/Leand91/Documents/PlexConnect-0.1-iOS-pre5.1"
set un to "admin"
set theKeychainItem to "plexappletv"
Thanks in advance!
Thanks all especially chrisbcole. Used the script with keychain support and all working well. Instead of hiding the running icon, I recommend adding a new icon to it and leaving it on the dock so it can be ‘managed’.
I’ve created a PlexConnect icon if anyone is looking for one.
Hey! Thanks to all those involved in Plex Connect and this tweak around it. It really means a lot!
I've made the app with applescript but I really can't get it to work.
In my case, my item is named:plexappletv; adminpassword:11; item username:admin; macusername:Leand91.
So we should change the values for these three variables thats it?:
set py to "path/to/PlexConnect.py"
set un to "username"
set theKeychainItem to "pw"And in my case that would be something like this?...
set py to "/Users/Leand91/Documents/PlexConnect-0.1-iOS-pre5.1"
set un to "admin"
set theKeychainItem to "plexappletv"
Thanks in advance!
un (username) is the account name that you are running the app from. The account field in keychain access is not used in the sample that was posted although it could be with some alterations.
I do want to take the opportunity to post a corrected version that shouldn't require the password when shutting down the app. I fixed it in my code a little while ago but forgot to update it here.
The main difference is to use the un and thePassword variables on quit as well as when launching PlexConnect. AppleScript apps stay authenticated as root for a period of time (less than 5 minutes) and thus I didn't notice the issue during initial testing.
Updated code:
set py to "path/to/PlexConnect.py" set un to "username" set theKeychainItem to "pw" #this is the name of the keychain item with your password in it #delay 10 #add this in or change the value as needed so that PlexConnect starts up after PMSset theResult to do shell script "security 2>&1 find-generic-password -gs " & theKeychainItem
set thePassword to extractData(theResult, “password: "”, “"”, 0)do shell script "screen -A -m -d -S PlexConnect " & py user name un password thePassword with administrator privileges
on quit
do shell script "screen -A -m -d -S kill " & “killps -u root | grep [P]lexConnect | grep python | awk '{print $2}'” user name un password thePassword with administrator privileges
continue quit
end quiton 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
Hope that helps.
un (username) is the account name that you are running the app from. The account field in keychain access is not used in the sample that was posted although it could be with some alterations.
I do want to take the opportunity to post a corrected version that shouldn't require the password when shutting down the app. I fixed it in my code a little while ago but forgot to update it here.
The main difference is to use the un and thePassword variables on quit as well as when launching PlexConnect. AppleScript apps stay authenticated as root for a period of time (less than 5 minutes) and thus I didn't notice the issue during initial testing.
Updated code:
set py to "path/to/PlexConnect.py" set un to "username" set theKeychainItem to "pw" #this is the name of the keychain item with your password in it #delay 10 #add this in or change the value as needed so that PlexConnect starts up after PMSset theResult to do shell script "security 2>&1 find-generic-password -gs " & theKeychainItem
set thePassword to extractData(theResult, “password: "”, “"”, 0)do shell script "screen -A -m -d -S PlexConnect " & py user name un password thePassword with administrator privileges
on quit
do shell script "screen -A -m -d -S kill " & “killps -u root | grep [P]lexConnect | grep python | awk '{print $2}'” user name un password thePassword with administrator privileges
continue quit
end quiton 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
Hope that helps.
i added the app to keychain access and password no needed when closing/opening it.
should i update the code ?
Thanks for the reply and updated code.
I still get this error message that has been adressed before.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
My script looks like this right now:
set py to "/Users/Leand91/Documents/PlexConnect-0.1-iOS-pre5.1"
set un to "Leand91"
set theKeychainItem to "plexappletv" #this is the name of the keychain item with your password in it
#delay 10 #add this in or change the value as needed so that PlexConnect starts up after PMS
set theResult to do shell script "security 2>&1 find-generic-password -gs " & theKeychainItem
set thePassword to extractData(theResult, "password: \"", "\"", 0)
do shell script "screen -A -m -d -S PlexConnect " & py user name un password thePassword with administrator privileges
on quit
do shell script "screen -A -m -d -S kill " & "kill `ps -u root | grep [P]lexConnect | grep python | awk '{print $2}'`" user name un password thePassword with administrator privileges
continue quit
end quit
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
Thanks for the reply and updated code.
I still get this error message that has been adressed before.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
Did a little research and testing and the only time I got this error was when the keychain item name (in your case plexconnect) was not matching the item name in keychain access. The other question is how your password is stored in Keychain Access. Is it a generic password (default application icon) or an Internet password (blue @ icon)? The script would only be looking for generic keychain items not internet items and therefore would be unable to locate them if that was how they were saved and that error would be thrown.
Thanks for the reply!
I got it working finally.
My keychain item name was plexappletv. I noticed that under the Location field it said "PlexConnect", so I changed the item name to plexconnect.
Updated the name on the script and the error disappeared.
But apart from that, I had another problem, since on the script I only specified the folder containing the PlexConnect.py file. Once I changed the path to the plexconnect.py file it started working.
Thanks again chrisbcole!
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:
- Kill all python threads associated with PlexConnect upon quitting
- Utilize all the data saved in the keychain item (not just password therefore it is much more generic)
- 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:
- 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)
- Create a generic keychain entry with your admin name as the account name and admin password as the password.
- 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.
Thanks again chrisbcole. One addition to this script, I added a delay back in to ensure PMS was already running before starting Plex Connect.
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:
- Kill all python threads associated with PlexConnect upon quitting
- Utilize all the data saved in the keychain item (not just password therefore it is much more generic)
- 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:
- 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)
- Create a generic keychain entry with your admin name as the account name and admin password as the password.
- 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 extractDataI see this as a very flexible solution especially if updating source regularly or bouncing between different branches.
Hope this helps.
thanks.
the change that i see is when quitting the app normally buy cmd+q phyton processes are closing too.
thanks so much !
The only issue left that I have is that I need to quit the App from the task manager. It won't exit on itself when I want to shut off the computer.
That last updated code would fix that?
Thanks