Skip to content

OSX notifications in a pluggable architecture for other kinds of notifications.

Notifications You must be signed in to change notification settings

apdunston/notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notifier

OSX notifications in a pluggable architecture for other kinds of notifications.

Borrows heavily from the fabulous navinpeiris/ex_unit_notifier! Thanks, Navin. You're awesome.

demo

Requirements

For icon support, you must install terminal-notifier

> brew install terminal-notifier

Usage

Add it to your dependencies

# mix.exs
def deps do
  [{:notifier, "~> 0.0.1"}]
end
> mix deps.get
Notifier.notify("This is my message.")

Notifier.notify("MY TITLE", "This is my message.")

# All the options, local image
Notifier.notify(%{
  title: "MY TITLE", 
  message: "This is my message.",
  sound: "Basso",
  icon: "/Users/yourname/Pictures/cute_picture.png"
})

# All the options, remote image
Notifier.notify(%{
  title: "MY TITLE", 
  message: "This is my message.",
  sound: "Basso",
  icon: "http://www.gnu.org/graphics/heckert_gnu.small.png"
})

# Some options
Notifier.notify(%{
  sound: "Basso", 
  title: "MY TITLE", 
  message: "This is my message."
})

# Fewer options
Notifier.notify(%{title: "MY TITLE", message: "This is my message."})
Notifier.notify(%{title: "MY TITLE"})
Notifier.notify(%{message: "This is my message."})

Selecting a Plugin

You may optionally specify which plugin Notifier uses.

config.exs

config :notifier, :plugin, Notifier.TerminalNotifierPlugin
# config :notifier, :plugin, Notifier.ApplescriptPlugin
# config :notifier, :plugin, Notifier.PutsPlugin

Adding your own Plugin

Let's say you want to use Growl or some other style of notification. No problem! Implement the Notifier.Plugin behavior like so:

defmodule Notifier.MyPlugin do
  @behaviour Notifier.Plugin

  def notify(%{title: title, message: message, sound: sound, icon: icon}) do
    # Whatever magic you do to notify the person at the screen.
  end

  def available? do
    # Return true if this plugin will work in this environment, false otherwise.
  end
end

Then set your config to use your notifier.

config.exs

config :notifier, :plugin, MyNamespace.MyPlugin

If you do this, I'd love a pull request so I can add it to the package.

Acknowledgements

Thanks to Navin Peiris (http://navinpeiris.com) for code. Thanks to Spreedly (http://spreedly.com) for being a terrific place to work.

License

MIT License

Copyright (c) 2016 Adrian P. Dunston I

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

OSX notifications in a pluggable architecture for other kinds of notifications.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages