I tested it on macOS Sierra and it works properly. The script runs natively.
Remember to edit first two lines according to your installation.
Use at own risk and feel free to contribute.
@jay: I have often scripts that I want to make available for other users. Where is the appropriate place for this?
- Code: Select all
targetDirectoryZip = "/Users/USERNAME/Downloads/PlexUpdate.zip"
targetDirectory = "/Users/USERNAME/Downloads"
applicationDirectory = "/Applications"
import sys
import os
import subprocess
import urllib
import json
url = "https://plex.tv/api/downloads/1.json"
response = urllib.urlopen(url)
data = json.loads(response.read())
indigo.server.log("PLEX: Check for latest version")
#dumps the json object into an element
json_str = json.dumps(data)
#load the json to a string
resp = json.loads(json_str)
#extract an element in the response
updateUrl = resp['computer']['Mac']['releases'][0]['url']
versionNew = resp['computer']['Mac']['version']
#Use only the number of the build
sep = '-'
versionNew = versionNew.split(sep, 1)[0]
indigo.server.log("PLEX: Latest version is "+ versionNew)
import plistlib
versionOld = plistlib.readPlist("/Applications/Plex Media Server.app/Contents/Info.plist")
versionOld = versionOld["CFBundleVersion"]
indigo.server.log("PLEX: Installed version is "+ versionOld)
if versionOld != versionNew:
indigo.server.log("PLEX: Update required - downloading")
import urllib
testfile = urllib.URLopener()
testfile.retrieve(updateUrl, targetDirectoryZip)
indigo.server.log("PLEX: Download complete")
subprocess.call(['osascript', '-e', 'tell application "Plex Media Server" to quit'])
indigo.server.log("PLEX: Quit Plex Media Server")
os.system("rm -rf '/Applications/Plex Media Server.app'")
indigo.server.log("PLEX: Remove old version")
os.system("unzip " + targetDirectoryZip + " -d '/Applications'")
indigo.server.log("PLEX: Extraction complete")
os.remove(targetDirectoryZip)
indigo.server.log("PLEX: Remove temporary files")
subprocess.call(['osascript', '-e', 'tell application "Plex Media Server" to launch'])
indigo.server.log("PLEX: Starting Plex")
else:
indigo.server.log("PLEX: Update is not required")