Skip to content

ten16thomasg/go-toast

Repository files navigation

Beeper

A go toast notification package for Windows, Linux and macOS

Credits to:

CLI

Hacked together this small tool because I could not find a project that offered all of the features I wanted. Particularly the ability to pass a custom message and image paths as params, for all 3 commonly used platforms (Windows, macOS & Linux)

flag needs an argument: -img & -msg
Usage of C:\Example\beeper\main.go-windows-amd64.exe:
  -img string
        Enter a Custom Path (default "assets/information.png")
  -msg string
        Enter a Custom Message (default "Default BEEP BEEP!")
  -title string
        Enter a Custom Title (default "Title")

Example

This assumes you are familar with go and have a god development environment setup. The below was performed on windows, however thsi can be performed on macOS or Linux, change the commands as necessary.

  1. Make Directories and CD to beeper parent dir
C:\Example> mkdir beeper && mkdir beeper\assets
C:\Example> cd beeper
  1. Add Images to assets dir

  2. Create main go package

C:\Example\beeper> echo package main  > main.go
  1. Add Example Code
package main

import (
	"flag"
	"fmt"
	"reflect"

	"github.com/gen2brain/beeep"
)

func main() {
	//---Define the various flags---
	msgPtr := flag.String("msg", "Default BEEP BEEP!",
		"Enter a Custom Message")
	imgPth := flag.String("img", "assets/information.png",
		"Enter a Custom Path")
    titleNm := flag.String("title", "Title",
    "Enter a Custom Title")
	//---parse the command line into the defined flags---
	flag.Parse()
	err := beeep.Notify(*titleNm, *msgPtr, *imgPth)
	if err != nil {
		panic(err)
	}
	for _, arg := range flag.Args() {
		fmt.Print(arg, " ")
		fmt.Println(reflect.TypeOf(arg))
	}
}
  1. Init Directory
C:\Example\beeper> go mod init beeper
  1. Create Cross-Platform Build Bash/Bat file (On Windows I use git bash)
#!/usr/bin/env bash

package=$1
if [[ -z "$package" ]]; then
  echo "usage: $0 <package-name>"
  exit 1
fi
package_split=(${package//\// })
package_name=${package_split[-1]}
	
platforms=("windows/amd64" "windows/386" "darwin/amd64", "linux/amd64")

for platform in "${platforms[@]}"
do
	platform_split=(${platform//\// })
	GOOS=${platform_split[0]}
	GOARCH=${platform_split[1]}
	output_name=$package_name'-'$GOOS'-'$GOARCH
	if [ $GOOS = "windows" ]; then
		output_name+='.exe'
	fi	

	env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package
	if [ $? -ne 0 ]; then
   		echo 'An error has occurred! Aborting the script execution...'
		exit 1
	fi
done
  1. Build Binaries by running bash
$ ./build.bash main.go
  1. Test the binaries
$ ./main.go-windows-amd64.exe -img "assets/warning.png"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published