feat: Add terminal-notifier support for macOS notifications

This commit is contained in:
Paul Gauthier (aider) 2025-03-06 12:14:14 -08:00
parent 3da15bfd19
commit 47254be254

View file

@ -963,10 +963,14 @@ class InputOutput:
def get_default_notification_command(self):
"""Return a default notification command based on the operating system."""
import platform
system = platform.system()
if system == "Darwin": # macOS
# Check for terminal-notifier first
if shutil.which("terminal-notifier"):
return "terminal-notifier -title 'Aider' -message 'Aider is waiting for your input'"
# Fall back to osascript
return (
'osascript -e \'display notification "Aider is waiting for your input" with title'
' "Aider"\''
@ -988,7 +992,7 @@ class InputOutput:
" [System.Windows.Forms.MessageBox]::Show('Aider is waiting for your input',"
" 'Aider')\""
)
return None # Unknown system
def ring_bell(self):
@ -996,7 +1000,10 @@ class InputOutput:
if self.bell_on_next_input and self.notifications:
if self.notifications_command:
try:
subprocess.run(self.notifications_command, shell=True)
result = subprocess.run(self.notifications_command, shell=True, capture_output=True)
if result.returncode != 0 and result.stderr:
error_msg = result.stderr.decode('utf-8', errors='replace')
self.tool_warning(f"Failed to run notifications command: {error_msg}")
except Exception as e:
self.tool_warning(f"Failed to run notifications command: {e}")
else: