From 42e4edc6227c94b0cb34672e3a7dc5d246ce58e3 Mon Sep 17 00:00:00 2001 From: tcptps <50037207+tcptps@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:45:39 +0100 Subject: [PATCH 1/4] added an option to filter out system services --- pylaunchd_gui.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pylaunchd_gui.py b/pylaunchd_gui.py index 78be688..ac5b836 100644 --- a/pylaunchd_gui.py +++ b/pylaunchd_gui.py @@ -139,10 +139,10 @@ def exec(self, args): show_gui_error(str(args), err.decode('utf-8')) return result - def initialize_data(self, idx=0): + def initialize_data(self, idx=0, filter_system=False): try: self.tableView.tableModel.sendSignalLayoutAboutToBeChanged() - self.data[:] = self.load_data_launchctl(idx) + self.data[:] = self.load_data_launchctl(idx, filter_system) self.data_all[:] = self.data self.tableView.tableModel.sendSignalLayoutChanged() except Exception as e: @@ -193,12 +193,16 @@ def on_show_in_finder(self, which): else: show_gui_error("Please select a job first!") - def on_refresh(self, which): + def on_refresh(self, which, filter_system=False): domain_index = self.comboBoxDomain.currentIndex() self.statusBar().showMessage(f'Refreshing domain {LAUNCHD_DOMAINS[domain_index]} - please wait...') - self.initialize_data(domain_index) + self.initialize_data(domain_index, filter_system) self.statusBar().showMessage(f'Total jobs: {len(self.data)}') + def on_toggle_filter_system(self, which): + state = self.checkBoxFilterSystem.isChecked() + self.on_refresh(which, filter_system=state) + def createActions(self): self.actionOpenFile = QtWidgets.QAction( @@ -330,6 +334,9 @@ def createToolBars(self): self.comboBoxDomain.setCurrentIndex(self.domain_id) self.comboBoxDomain.activated.connect(self.on_domain_changed) self.toolBar.addWidget(self.comboBoxDomain) + self.checkBoxFilterSystem = QtWidgets.QCheckBox("filter out system services") + self.checkBoxFilterSystem.stateChanged.connect(self.on_toggle_filter_system) + self.toolBar.addWidget(self.checkBoxFilterSystem) self.toolBar.addAction(self.actionOpenFile) self.toolBar.addAction(self.actionStart) self.toolBar.addAction(self.actionStop) @@ -343,7 +350,7 @@ def createToolBars(self): self.searchBox.textChanged.connect(self.on_search_changed) self.toolBar.addWidget(self.searchBox) - def load_data_launchctl(self, domain_id=0): + def load_data_launchctl(self, domain_id=0, filter_system=False): data = [] uid = os.getuid() @@ -362,6 +369,11 @@ def load_data_launchctl(self, domain_id=0): label = line.split('\t')[-1] if label: details = self.exec(['launchctl', 'print', f'{domain}{user_identifier}/{label}']) + if filter_system: + properties = details.split('properties = {\n')[1].split('\t}')[0] + is_system = properties.split("system service = ")[1][0] + if is_system == "1": + continue self.jobs[label] = details paths = re.findall('^\s+path =\s(.*$)', details, re.MULTILINE) path = len(paths) and paths[0] or None From 26b63e1592da60fc572157c3362572a0ea91892a Mon Sep 17 00:00:00 2001 From: tcptps <50037207+tcptps@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:53:18 +0100 Subject: [PATCH 2/4] improvments to usability --- pylaunchd_gui.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pylaunchd_gui.py b/pylaunchd_gui.py index ac5b836..13516cb 100644 --- a/pylaunchd_gui.py +++ b/pylaunchd_gui.py @@ -139,10 +139,10 @@ def exec(self, args): show_gui_error(str(args), err.decode('utf-8')) return result - def initialize_data(self, idx=0, filter_system=False): + def initialize_data(self, idx=0): try: self.tableView.tableModel.sendSignalLayoutAboutToBeChanged() - self.data[:] = self.load_data_launchctl(idx, filter_system) + self.data[:] = self.load_data_launchctl(idx) self.data_all[:] = self.data self.tableView.tableModel.sendSignalLayoutChanged() except Exception as e: @@ -193,15 +193,14 @@ def on_show_in_finder(self, which): else: show_gui_error("Please select a job first!") - def on_refresh(self, which, filter_system=False): + def on_refresh(self, which): domain_index = self.comboBoxDomain.currentIndex() self.statusBar().showMessage(f'Refreshing domain {LAUNCHD_DOMAINS[domain_index]} - please wait...') - self.initialize_data(domain_index, filter_system) + self.initialize_data(domain_index) self.statusBar().showMessage(f'Total jobs: {len(self.data)}') def on_toggle_filter_system(self, which): - state = self.checkBoxFilterSystem.isChecked() - self.on_refresh(which, filter_system=state) + self.on_refresh(which) def createActions(self): @@ -350,7 +349,7 @@ def createToolBars(self): self.searchBox.textChanged.connect(self.on_search_changed) self.toolBar.addWidget(self.searchBox) - def load_data_launchctl(self, domain_id=0, filter_system=False): + def load_data_launchctl(self, domain_id=0): data = [] uid = os.getuid() @@ -369,7 +368,7 @@ def load_data_launchctl(self, domain_id=0, filter_system=False): label = line.split('\t')[-1] if label: details = self.exec(['launchctl', 'print', f'{domain}{user_identifier}/{label}']) - if filter_system: + if self.checkBoxFilterSystem.isChecked(): properties = details.split('properties = {\n')[1].split('\t}')[0] is_system = properties.split("system service = ")[1][0] if is_system == "1": From 439172333836d0bf8adc677d2d24d8f23ecdb3d5 Mon Sep 17 00:00:00 2001 From: tcptps <50037207+tcptps@users.noreply.github.com> Date: Fri, 10 Mar 2023 23:44:25 +0100 Subject: [PATCH 3/4] fixed ventura --- pylaunchd_gui.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pylaunchd_gui.py b/pylaunchd_gui.py index 13516cb..227de2b 100644 --- a/pylaunchd_gui.py +++ b/pylaunchd_gui.py @@ -364,14 +364,18 @@ def load_data_launchctl(self, domain_id=0): services = gui_processes.split('services = {\n')[1].split('\t}')[0] + for line in services.splitlines(): label = line.split('\t')[-1] if label: details = self.exec(['launchctl', 'print', f'{domain}{user_identifier}/{label}']) if self.checkBoxFilterSystem.isChecked(): - properties = details.split('properties = {\n')[1].split('\t}')[0] - is_system = properties.split("system service = ")[1][0] - if is_system == "1": + properties = details.split('properties = {\n')[1].split('}')[0] + if "=" in properties: + is_system = properties.split("system service = ")[1][0] + if is_system == "1": + continue + elif "system service" in properties : continue self.jobs[label] = details paths = re.findall('^\s+path =\s(.*$)', details, re.MULTILINE) From 39054ce4075555a6ba3f5dee966bb7a17c75375d Mon Sep 17 00:00:00 2001 From: tcptps <50037207+tcptps@users.noreply.github.com> Date: Sat, 11 Mar 2023 02:02:23 +0100 Subject: [PATCH 4/4] fix for ventura 2.0 --- pylaunchd_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylaunchd_gui.py b/pylaunchd_gui.py index 227de2b..1bc6feb 100644 --- a/pylaunchd_gui.py +++ b/pylaunchd_gui.py @@ -370,7 +370,7 @@ def load_data_launchctl(self, domain_id=0): if label: details = self.exec(['launchctl', 'print', f'{domain}{user_identifier}/{label}']) if self.checkBoxFilterSystem.isChecked(): - properties = details.split('properties = {\n')[1].split('}')[0] + properties = details.split('properties = ')[1].split('}')[0] if "=" in properties: is_system = properties.split("system service = ")[1][0] if is_system == "1":