### Install terminal-notifier via Package Managers Source: https://github.com/julienxx/terminal-notifier/blob/master/README.markdown Instructions for installing the terminal-notifier tool using RubyGems or Homebrew on macOS. ```bash # Install via RubyGems [sudo] gem install terminal-notifier # Install via Homebrew brew install terminal-notifier ``` -------------------------------- ### Install TerminalNotifier Gem Source: https://github.com/julienxx/terminal-notifier/blob/master/Ruby/README.markdown Instructions to install the terminal-notifier Ruby gem using the gem command. This is the primary method for adding the gem to your Ruby environment. ```bash $ gem install terminal-notifier ``` -------------------------------- ### Send macOS Notifications via CLI Source: https://github.com/julienxx/terminal-notifier/blob/master/README.markdown Examples of using the terminal-notifier binary to send notifications with various options such as piped data, custom icons, URL opening, and app activation. ```bash # Display piped data with a sound echo 'Piped Message Data!' | terminal-notifier -sound default # Use a custom icon terminal-notifier -title ProjectX -subtitle "new tag detected" -message "Finished" -appIcon http://vjeantet.fr/images/logo.png # Open a URL when the notification is clicked terminal-notifier -title '💰' -message 'Check your Apple stock!' -open 'http://finance.yahoo.com/q?s=AAPL' # Open an app when the notification is clicked terminal-notifier -group 'address-book-sync' -title 'Address Book Sync' -subtitle 'Finished' -message 'Imported 42 contacts.' -activate 'com.apple.AddressBook' ``` -------------------------------- ### Shell Script Build Notifications Source: https://context7.com/julienxx/terminal-notifier/llms.txt Sends notifications for build start, success, or failure using the terminal-notifier command-line tool. It integrates with shell scripts and checks the exit status of the 'make build' command. ```shell # Start build notification terminal-notifier -group "build-$PROJECT" -title "$PROJECT" -message "Build started..." # Run the build if make build 2>&1; then terminal-notifier -group "build-$PROJECT" -title "$PROJECT" \ -subtitle "Success" -message "Build completed successfully" \ -sound Glass -open "file://$(pwd)/build/" else terminal-notifier -group "build-$PROJECT" -title "$PROJECT" \ -subtitle "Failed" -message "Build failed! Check logs." \ -sound Basso -activate "com.apple.Terminal" fi ``` -------------------------------- ### Ruby Long-Running Process Monitor Source: https://context7.com/julienxx/terminal-notifier/llms.txt A Ruby function that wraps a command execution with notifications for start, success, and failure. It measures execution duration and provides feedback via terminal-notifier. ```ruby require 'terminal-notifier' def run_with_notification(command, title: 'Task') group_id = "task-#{Process.pid}" TerminalNotifier.notify("Starting: #{command}", :title => title, :group => group_id ) start_time = Time.now success = system(command) duration = (Time.now - start_time).round(1) if success TerminalNotifier.notify("Completed in #{duration}s", :title => title, :subtitle => 'Success', :group => group_id, :sound => 'default' ) else TerminalNotifier.notify("Failed after #{duration}s", :title => title, :subtitle => 'Error', :group => group_id, :sound => 'Basso' ) end success end # Usage run_with_notification('bundle exec rspec', title: 'Test Suite') run_with_notification('npm run build', title: 'Frontend Build') ``` -------------------------------- ### Ruby Rake Task Deployment Notifications Source: https://context7.com/julienxx/terminal-notifier/llms.txt Integrates native macOS notifications into Ruby Rake tasks for deployment processes. It sends notifications for the start of deployment, success, and failure, including error messages. ```ruby require 'terminal-notifier' namespace :deploy do task :production do TerminalNotifier.notify('Starting deployment...', :title => 'Deploy', :group => 'deploy-prod' ) begin # Deployment logic here Rake::Task['deploy:execute'].invoke TerminalNotifier.notify('Deployment successful!', :title => 'Deploy', :subtitle => 'Production', :group => 'deploy-prod', :sound => 'default', :open => 'https://myapp.com' ) rescue => e TerminalNotifier.notify("Deployment failed: #{e.message}", :title => 'Deploy', :subtitle => 'Production', :group => 'deploy-prod', :sound => 'Basso' ) raise end end end ``` -------------------------------- ### Cron Job Notification with Terminal-Notifier (Shell) Source: https://github.com/julienxx/terminal-notifier/wiki/Tips-and-Tricks This snippet demonstrates how to use terminal-notifier within a Cron job to send notifications based on command execution status. It checks the exit code of a series of commands and sends a success or failure message accordingly. Ensure terminal-notifier is installed and accessible in your PATH. ```shell # CronJobNotifier # this is a test /opt/local/bin/terminal-notifier -title cron -subtitle "test" -message "job ready to run" -execute ' # start of commands true && false && true # end of commands if [ $? -ne 0 ] ; then /opt/local/bin/terminal-notifier -title cron -subtitle "test" -message "job failed, run manually" ; else /opt/local/bin/terminal-notifier -title cron -subtitle "test" -message "job run successfully" ; fi ' ``` -------------------------------- ### CLI: Create Notification Source: https://context7.com/julienxx/terminal-notifier/llms.txt Sends a user notification to the macOS Notification Center via command line arguments. ```APIDOC ## POST /notify (CLI) ### Description Displays a notification on the macOS desktop. Use the -group flag to enable deduplication. ### Method CLI Execution ### Parameters #### Query Parameters - **-message** (string) - Required - The body text of the notification. - **-title** (string) - Optional - The title of the notification. - **-group** (string) - Optional - A unique identifier for grouping/updating notifications. - **-ignoreDnD** (flag) - Optional - Force display even when Do Not Disturb is enabled. ### Request Example terminal-notifier -group "build-status" -title "Build" -message "Building project..." ### Response #### Success Response (0) - **Exit Code** (int) - Returns 0 on success. ``` -------------------------------- ### CLI/Ruby: List Notifications Source: https://context7.com/julienxx/terminal-notifier/llms.txt Retrieves details about currently active notifications. ```APIDOC ## GET /list ### Description Returns a list of active notifications. CLI output is tab-separated; Ruby returns a hash or array of hashes. ### Response #### Success Response - **data** (array/hash) - Contains group, title, subtitle, message, and delivered_at timestamp. ``` -------------------------------- ### Check Availability via Ruby API Source: https://context7.com/julienxx/terminal-notifier/llms.txt Verify if the terminal-notifier utility is supported on the current macOS environment before attempting to send notifications. ```ruby require 'terminal-notifier' if TerminalNotifier.available? TerminalNotifier.notify('Hello from macOS!') end ``` -------------------------------- ### Manage Notifications via CLI Source: https://context7.com/julienxx/terminal-notifier/llms.txt Use the terminal-notifier command-line tool to send, remove, and list notifications. Supports grouping by ID, ignoring Do Not Disturb, and parsing output in shell scripts. ```bash terminal-notifier -group "build-status" -title "Build" -message "Building project..." terminal-notifier -remove "build-status" terminal-notifier -list ALL ``` -------------------------------- ### Send macOS Notifications with TerminalNotifier (Ruby) Source: https://github.com/julienxx/terminal-notifier/blob/master/Ruby/README.markdown Demonstrates various ways to send notifications using the TerminalNotifier gem in Ruby. It covers basic messages, adding titles and subtitles, activating applications, opening URLs, executing commands, grouping notifications, specifying the sender, and using notification sounds. ```ruby TerminalNotifier.notify('Hello World') TerminalNotifier.notify('Hello World', :title => 'Ruby', :subtitle => 'Programming Language') TerminalNotifier.notify('Hello World', :activate => 'com.apple.Safari') TerminalNotifier.notify('Hello World', :open => 'http://twitter.com/julienXX') TerminalNotifier.notify('Hello World', :execute => 'say "OMG"') TerminalNotifier.notify('Hello World', :group => Process.pid) TerminalNotifier.notify('Hello World', :sender => 'com.apple.Safari') TerminalNotifier.notify('Hello World', :sound => 'default') ``` -------------------------------- ### Ruby: TerminalNotifier.notify Source: https://context7.com/julienxx/terminal-notifier/llms.txt Sends a user notification from a Ruby application with support for advanced features like sounds, URLs, and app activation. ```APIDOC ## POST TerminalNotifier.notify ### Description Sends a notification using the Ruby gem interface. ### Method Ruby Method Call ### Parameters #### Request Body - **message** (string) - Required - The notification body. - **options** (hash) - Optional - Includes :title, :subtitle, :sound, :open (URL), :activate (bundle ID), :execute (command), :group, and :sender. ### Request Example TerminalNotifier.notify('Build completed!', :title => 'Ruby Project', :sound => 'default') ### Response #### Success Response - **Result** (symbol/string) - Returns a symbol representing the result or reply text. ``` -------------------------------- ### List Active Notifications via Ruby API Source: https://context7.com/julienxx/terminal-notifier/llms.txt Retrieve details about currently active notifications. Returns a hash for specific groups or an array of hashes for all notifications. ```ruby require 'terminal-notifier' notifications = TerminalNotifier.list notifications.each { |n| puts "#{n[:title]}: #{n[:message]}" } ``` -------------------------------- ### Send Notifications via Ruby API Source: https://context7.com/julienxx/terminal-notifier/llms.txt The TerminalNotifier Ruby gem provides a wrapper for macOS notifications. It supports advanced features like sound, URL opening, app activation, and command execution on click. ```ruby require 'terminal-notifier' TerminalNotifier.notify('Hello World', :title => 'Ruby Project', :sound => 'default', :open => 'http://github.com/julienXX/terminal-notifier') ``` -------------------------------- ### Manage Notifications with TerminalNotifier (Ruby) Source: https://github.com/julienxx/terminal-notifier/blob/master/Ruby/README.markdown Shows how to manage notifications using the TerminalNotifier gem in Ruby. This includes removing specific notifications by their process ID and listing active notifications. ```ruby TerminalNotifier.remove(Process.pid) TerminalNotifier.list(Process.pid) TerminalNotifier.list ``` -------------------------------- ### Cron Job Notifications Source: https://context7.com/julienxx/terminal-notifier/llms.txt Notifies on cron job execution results. This bash script snippet demonstrates how to use terminal-notifier within a crontab entry to report success or failure of a backup script. ```bash # Add to crontab with: crontab -e # Run backup every day at 2am and notify on result 0 2 * * * /path/to/backup.sh && terminal-notifier -title "Backup" -message "Daily backup completed" -sound default || terminal-notifier -title "Backup" -message "Backup FAILED!" -sound Basso ``` -------------------------------- ### CLI/Ruby: Remove Notifications Source: https://context7.com/julienxx/terminal-notifier/llms.txt Removes previously posted notifications based on their group ID. ```APIDOC ## DELETE /remove ### Description Removes notifications associated with a specific group ID or all notifications. ### Parameters #### Path Parameters - **group_id** (string) - Required - The ID used during notification creation or 'ALL'. ### Request Example # CLI terminal-notifier -remove "build-status" # Ruby TerminalNotifier.remove('my-group-id') ``` -------------------------------- ### Remove Notifications via Ruby API Source: https://context7.com/julienxx/terminal-notifier/llms.txt Remove previously posted notifications using a group ID or process ID. Returns a boolean indicating the success of the removal operation. ```ruby require 'terminal-notifier' if TerminalNotifier.remove('build-status') puts "Notification removed successfully" end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.