From 48dd88df7568ed6d8c957203d152f23281cba83b Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Thu, 15 Dec 2022 17:02:36 -0500 Subject: [PATCH] Support -open arg with terminal-notifier (macosx://) (#789) --- apprise/plugins/NotifyMacOSX.py | 20 +++++++++++++++++++- test/test_plugin_macosx.py | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apprise/plugins/NotifyMacOSX.py b/apprise/plugins/NotifyMacOSX.py index 2e12d389..5c0b1063 100644 --- a/apprise/plugins/NotifyMacOSX.py +++ b/apprise/plugins/NotifyMacOSX.py @@ -121,9 +121,13 @@ class NotifyMacOSX(NotifyBase): 'name': _('Sound'), 'type': 'string', }, + 'click': { + 'name': _('Open/Click URL'), + 'type': 'string', + }, }) - def __init__(self, sound=None, include_image=True, **kwargs): + def __init__(self, sound=None, include_image=True, click=None, **kwargs): """ Initialize MacOSX Object """ @@ -137,6 +141,10 @@ class NotifyMacOSX(NotifyBase): self.notify_path = next( # pragma: no branch (p for p in self.notify_paths if os.access(p, os.X_OK)), None) + # Click URL + # Allow user to provide the `--open` argument on the notify wrapper + self.click = click + # Set sound object (no q/a for now) self.sound = sound @@ -162,6 +170,9 @@ class NotifyMacOSX(NotifyBase): if title: cmd.extend(['-title', title]) + if self.click: + cmd.extend(['-open', self.click]) + # The sound to play if self.sound: cmd.extend(['-sound', self.sound]) @@ -203,6 +214,9 @@ class NotifyMacOSX(NotifyBase): 'image': 'yes' if self.include_image else 'no', } + if self.click: + params['click'] = self.click + # Extend our parameters params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) @@ -230,6 +244,10 @@ class NotifyMacOSX(NotifyBase): results['include_image'] = \ parse_bool(results['qsd'].get('image', True)) + # Support 'click' + if 'click' in results['qsd'] and len(results['qsd']['click']): + results['click'] = NotifyMacOSX.unquote(results['qsd']['click']) + # Support 'sound' if 'sound' in results['qsd'] and len(results['qsd']['sound']): results['sound'] = NotifyMacOSX.unquote(results['qsd']['sound']) diff --git a/test/test_plugin_macosx.py b/test/test_plugin_macosx.py index ac6519bc..b0cbb7c6 100644 --- a/test/test_plugin_macosx.py +++ b/test/test_plugin_macosx.py @@ -126,6 +126,15 @@ def test_plugin_macosx_general_success(macos_notify_environment): assert obj.notify(title='title', body='body', notify_type=apprise.NotifyType.INFO) is True + # Test Click (-open support) + obj = apprise.Apprise.instantiate( + 'macosx://_/?click=http://google.com', suppress_exceptions=False) + assert isinstance(obj, NotifyMacOSX) is True + assert obj.click == 'http://google.com' + assert isinstance(obj.url(), str) is True + assert obj.notify(title='title', body='body', + notify_type=apprise.NotifyType.INFO) is True + def test_plugin_macosx_terminal_notifier_not_executable( pretend_macos, terminal_notifier):