Can I send a notification from Matlab to the Notification Center in OSX?

I want to send a notification when my Matlab code is launched in the Notification Center. I am on Mountain Lion 10.8.3 and have Matlab 2012b. Is it possible? If so, how?

+4
source share
4 answers

Here is the full function. It displays Matlab as a name and icon, and clicking on the notification takes you to Matlab:

function notify(message) escaped_message = strrep(message, '"', '\"'); [~, ~] = system(['/usr/local/bin/terminal-notifier ' ... '-title Matlab ' ... '-group com.mathworks.matlab ' ... '-activate com.mathworks.matlab ' ... '-sender com.mathworks.matlab ' ... '-message "' escaped_message '"']); end 
+3
source

terminal-notifier is a tool for "sending user notifications on Mac OS X 10.8 from the command line." Matlab can send commands to the command line of Mac OS X using system or ! . Combining them, you can write something like this in your m files:

 !terminal-notifier.app/Contents/MacOS/terminal-notifier -message "Testing..." 

To simplify the task, you probably want to create your own function so that you can call it like this:

 notify("Notifications from Matlab!") 
+2
source

To add to the solutions, here's how to do it using the Matlab system function and the osascript terminal osascript , which runs AppleScript from the command line. The function below takes a message argument and optional title , subtitle and alert arguments. A raw input leak is also performed. The alert sound arguments can be any of the named sounds on the Sound Effects tab of the Sound panel in System Preferences, for example, 'Sosumi' .

 function status=notify(msg,titl,subtitl,alert) %NOTIFY Display OS X notification message window % NOTIFY(MESSAGE,TITLE,SUBTITLE,SOUND) rep = @(str)strrep(regexprep(str,'["\\]','\\$0'),'''','\"'); cmd = ['osascript -e ''display notification "' rep(msg)]; if nargin > 1 && ischar(titl) cmd = [cmd '" with title "' rep(titl)]; if nargin > 2 && ischar(subtitl) cmd = [cmd '" subtitle "' rep(subtitl)]; if nargin > 3 && ischar(alert) && ~isempty(alert) cmd = [cmd '" sound name "' rep(alert)]; end end else cmd = [cmd '" with title "Matlab']; end status = system([cmd '"''']); 

You can download a more complete version of this feature from my GitHub . Unlike terminal-notifier , I don’t believe that the notification menu icon can be changed. However, this function should work on any OS X 10.8 or 10.9 system and does not require installing or downloading any files. This code has been tested in accordance with OS X 10.9.3 and 10.11.4.

+2
source

use two functions:

  • run matlab from bash
  • say done or say error ( more )

    matlab -nojvm -nodesktop -r "run.m" && & & let's say || say mistake

+1
source

All Articles