Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirected to applescript editor on clicking apple notification

I am using

osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'

to display notifications in Mac. However, on clicking the notification, I am getting redirected to the applescript editor. Is it possible for me to redirect the user to a url or open up a directory on clicking the notification which is generated?

like image 606
Pradeep Vairamani Avatar asked Jul 07 '14 08:07

Pradeep Vairamani


1 Answers

The run handler will only get called if the script is saved as an app, preferably a stay-open app. In any case, the app has to be still running when someone clicks the notification. You won't get this behavior from a simple osascript string.

You could get osascript to run a compiled script file (which can store properties persistently), but you will still need to distinguish between the run event that happens when you run the script, and the run event that gets called when someone clicks the notification.

I can suggest a couple of solutions here.

  • Use a python library to fire off notifications and forget about appleScript/OSA. You can find some information, and various solutions at this stackoverflow link: Python post osx notification

  • Set up a stay-open appleScript app as a kind of 'notification server' and send a message to that (possibly with OSAscript, unless you can send a raw apple event to the 'server' from python) when you want to set up some notification intercourse. This is tricky, and seems overcomplex, compared to my first suggestion. In particular, you may still need to mess about with the privacy settings (especially if on Mavericks or later) to allow OSAscript access to system events.

Here are a couple of links which may guide you with the latter approach, but I really thing the first suggestion will get you further, with fewer tears:

http://jacobsalmela.com/bash-script-enable-access-assistive-devices-programmatically-os-x-mavericks-10-9-x-simulate-keystrokes/

http://support.apple.com/kb/HT6026?viewlocale=en_US&locale=en_US

like image 118
brennanyoung Avatar answered Oct 05 '22 10:10

brennanyoung