From e546689e015abcce5c00ebd00d4a17492951d560 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sun, 26 Apr 2020 21:32:37 -0700 Subject: [PATCH] Check if MacOS login item exists before adding --- plexpy/macos.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plexpy/macos.py b/plexpy/macos.py index 2169eb4d..d7effcf5 100644 --- a/plexpy/macos.py +++ b/plexpy/macos.py @@ -108,9 +108,13 @@ def set_startup(): if plexpy.INSTALL_TYPE == 'macos': if plexpy.CONFIG.LAUNCH_STARTUP: try: - subprocess.Popen(['osascript', '-e', - 'tell application "System Events" to make login item at end with properties ' - '{path:"/Applications/Tautulli.app", hidden:false}']) + subprocess.Popen(['osascript', + '-e', 'tell application "System Events"', + '-e', 'get the name of every login item', + '-e', 'if not exists login item "Tautulli" then ' + 'make login item at end with properties ' + '{path:"/Applications/Tautulli.app", hidden:false}', + '-e', 'end tell']) logger.info("Added Tautulli to MacOS login items.") return True except OSError as e: @@ -119,8 +123,12 @@ def set_startup(): else: try: - subprocess.Popen(['osascript', '-e', - 'tell application "System Events" to delete login item "Tautulli"']) + subprocess.Popen(['osascript', + '-e', 'tell application "System Events"', + '-e', 'get the name of every login item', + '-e', 'if exists login item "Tautulli" then ' + 'delete login item "Tautulli"', + '-e', 'end tell']) logger.info("Removed Tautulli from MacOS login items.") return True except OSError as e: