Skip to content

Commit

Permalink
Support -open arg with terminal-notifier (macosx://) (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Dec 15, 2022
1 parent 5e8a2d2 commit 48dd88d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 19 additions & 1 deletion apprise/plugins/NotifyMacOSX.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -137,6 +141,10 @@ def __init__(self, sound=None, include_image=True, **kwargs):
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

Expand All @@ -162,6 +170,9 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
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])
Expand Down Expand Up @@ -203,6 +214,9 @@ def url(self, privacy=False, *args, **kwargs):
'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))

Expand Down Expand Up @@ -230,6 +244,10 @@ def parse_url(url):
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'])
Expand Down
9 changes: 9 additions & 0 deletions test/test_plugin_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 48dd88d

Please sign in to comment.