• Stars
    star
    585
  • Rank 76,419 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

gosx-notifier is a Go framework for sending desktop notifications to OSX 10.8 or higher

gosx-notifier

A Go lib for sending desktop notifications to OSX Mountain Lion's (10.8 or higher REQUIRED) Notification Center.

GoDoc

Update 4/3/2014

On OSX 10.9 and above gosx-notifier now supports images and icons. Now with custom icon support

Synopsis

OSX Mountain Lion comes packaged with a built-in notification center. For whatever reason, Apple sandboxed the notification center API to apps hosted in its App Store. The end result? A potentially useful API shackled to Apple's ecosystem.

Thankfully, Eloy DurΓ‘n put together an osx app that allows terminal access to the sandboxed API. gosx-notifier embeds this app with a simple interface to the closed API.

It's not perfect, and the implementor will quickly notice its limitations. However, it's a start and any pull requests are accepted and encouraged!

Dependencies:

There are none! If you utilize this package and create a binary executable it will auto-magically install the terminal-notifier component into a temp directory of the server. This is possible because in this latest version the terminal-notifier binary is now statically embedded into the Go source files.

Installation and Requirements

The following command will install the notification api for Go along with the binaries. Also, utilizing this lib requires OSX 10.8 or higher. It will simply not work on lower versions of OSX.

go get github.com/deckarep/gosx-notifier

Using the Command Line

notify "Wow! A notification!!!"

useful for knowing when long running commands finish

longRunningCommand && notify done!

Using the Code

It's a pretty straightforward API:

package main

import (
    "github.com/deckarep/gosx-notifier"
    "log"
)

func main() {
    //At a minimum specifiy a message to display to end-user.
    note := gosxnotifier.NewNotification("Check your Apple Stock!")

    //Optionally, set a title
    note.Title = "It's money making time πŸ’°"

    //Optionally, set a subtitle
    note.Subtitle = "My subtitle"

    //Optionally, set a sound from a predefined set.
    note.Sound = gosxnotifier.Basso

    //Optionally, set a group which ensures only one notification is ever shown replacing previous notification of same group id.
    note.Group = "com.unique.yourapp.identifier"

    //Optionally, set a sender (Notification will now use the Safari icon)
    note.Sender = "com.apple.Safari"

    //Optionally, specifiy a url or bundleid to open should the notification be
    //clicked.
    note.Link = "http://www.yahoo.com" //or BundleID like: com.apple.Terminal

    //Optionally, an app icon (10.9+ ONLY)
    note.AppIcon = "gopher.png"

    //Optionally, a content image (10.9+ ONLY)
    note.ContentImage = "gopher.png"

    //Then, push the notification
    err := note.Push()

    //If necessary, check error
    if err != nil {
        log.Println("Uh oh!")
    }
}

Sample App: Desktop Pinger Notification - monitors your websites and will notifiy you when a website is down.

package main

import (
	"github.com/deckarep/gosx-notifier"
	"net/http"
	"strings"
	"time"
)

//a slice of string sites that you are interested in watching
var sites []string = []string{
	"http://www.yahoo.com",
	"http://www.google.com",
	"http://www.bing.com"}

func main() {
	ch := make(chan string)

	for _, s := range sites {
		go pinger(ch, s)
	}

	for {
		select {
		case result := <-ch:
			if strings.HasPrefix(result, "-") {
				s := strings.Trim(result, "-")
				showNotification("Urgent, can't ping website: " + s)
			}
		}
	}
}

func showNotification(message string) {

	note := gosxnotifier.NewNotification(message)
	note.Title = "Site Down"
	note.Sound = gosxnotifier.Default

	note.Push()
}

//Prefixing a site with a + means it's up, while - means it's down
func pinger(ch chan string, site string) {
	for {
		res, err := http.Get(site)

		if err != nil {
			ch <- "-" + site
		} else {
			if res.StatusCode != 200 {
				ch <- "-" + site
			} else {
				ch <- "+" + site
			}
			res.Body.Close()
		}
		time.Sleep(30 * time.Second)
	}
}

Usage Ideas

  • Monitor your awesome server cluster and push notifications when something goes haywire (we've all been there)
  • Scrape Hacker News looking for articles of certain keywords and push a notification
  • Monitor your stock performance, push a notification, before you lose all your money
  • Hook it up to ifttt.com and push a notification when your motion-sensor at home goes off

Coming Soon

  • Remove ID

Licence

This project is dual licensed under any licensing defined by the underlying apps and MIT licensed for this version written in Go.

Bitdeli Badge

More Repositories

1

golang-set

A simple, battle-tested and generic set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.
Go
3,971
star
2

EasyCert

EasyCert quickly generates web server TLS certificates that have been self-signed by a private certificate authority that it also creates.
Go
134
star
3

flappy-rust

A Rust SDL2 clone of Flappy Gopher which is a clone of Flappy Bird
Rust
66
star
4

sync-map-analysis

Comparing usage and performance of Go's regular map backed by a RWLock vs sync.map.
Go
38
star
5

blade

a remote SSH command-line runner based on YAML recipe files.
Go
31
star
6

corebench

corebench - run your benchmarks against high performance computing servers with many CPU cores
Go
30
star
7

apfs-compactor

Compaction tool proof-of-concept for deduplicating files and saving more space by exploiting APFS with the goal of saving disk space.
Go
28
star
8

KaraokeBerry

KaraokeBerry is a Python based web-app that allows you to play Karaoke CDG/MP3 files on your Raspberry Pi and remotely choose songs, manage a queue and host a Karaoke party from your mobile devices without ever touching the Raspberry Pi.
Python
26
star
9

ziglang-set

A generic and general purpose Set implementation for the Zig language
Zig
21
star
10

objective-go

Some examples of calling Objective-C code using Cgo from the Go programming language.
Go
8
star
11

zig-notebook

A repository to mess around in the Zig language - try things out, record notes, etc.
C
7
star
12

TornadoZeroMQ-WS-Demo

Demonstrates using Tornado Web Sockets with data published from a ZeroMQ process.
6
star
13

zig-agi

Classic Sierra AGI Interpreter in Zig
C
4
star
14

Nebula

Three.js Chrome visual experiment by Airtight
JavaScript
4
star
15

karaoke4go

An implementation of the Karaoke CDG file-format for Go
JavaScript
4
star
16

garyburd_websocket

http://gary.beagledreams.com/page/go-websocket-chat.html
Go
3
star
17

sci-hacking

Information on reverse engineering, hacking and patching classic SCI Sierra games with ScummVM
3
star
18

tips

tips: The command-line tool to wrangle your Tailscale tailnet cluster whether large or small.
Go
3
star
19

performance-go

A repository dedicated to writing performant Go.
2
star
20

SCI-Rave-Hires-Portrait-Encoder

A utility to encode RAVE Hires Character Portraits for the Sierra game King's Quest 6
Go
2
star
21

all-about-dem-virtual-machines

Repo for my notes on creating interpreters/virtual machines
2
star
22

raylib-coro-demo

Raylib with coroutines using the C-based neco project
C++
2
star
23

benchstat-js

Benchstat.js -- allows you to paste in Go benchmarks and have them analyzed by Benchstat
JavaScript
2
star
24

upload-go

Examples in multipart uploading
Go
2
star
25

eazy-duz-it

Python
1
star
26

python-vm-internals

Inspecting Python3 bytecode internals - with some notes
Python
1
star
27

ofKaraoke

Karaoke CDG app made with OpenFrameworks platform using C++
C++
1
star
28

cloud-chromioke

Chromecast Karaoke in the Cloud
Shell
1
star
29

pyxel-chip8

The CHIP-8 virtual machine implemented in the Pyxel fantasy console.
Python
1
star
30

lc3-zig

The LC3 virtual machine implemented in Zig.
Zig
1
star
31

harmony

Procedural Drawing Tool
JavaScript
1
star
32

bin-patcher

a descriptor based patching sequencer
Go
1
star
33

kafka-websocket-consumer

Consumes from Kafka and sends writes data to an HTML websocket connection.
Go
1
star
34

resume-template

Fork this, fill out the resume.json, turn-on GitHub Pages and Rock On!
JavaScript
1
star
35

gorganize

Just some durrdy code to move files around and organize shit...mostly photos and videos.
Go
1
star
36

GoQuest

A simple room-based adventure game that the world can play.
Go
1
star