Matt Parkinson

MSci + ARCS + PhD + DIC

Analytical Scientist

NMR Spectroscopist

Doodle Creator

Maker

Matt Parkinson

MSci + ARCS + PhD + DIC

Analytical Scientist

NMR Spectroscopist

Doodle Creator

Maker

Project

Custom Icon for Terminal-Notification

03 Nov 2013 Archived, IT

Will all my automation scripts I needed an easy way to monotor their status. One solution is to create a status script which output some test which is display on my desktop using GeekTool. Although I hace being disturbed by system notifications, I don’t mind them if they are from me telling my my webserver is down or my temperatureing logging has failed.

I found this command line tool called terminal-notification which sends notification to the systems:
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "The Title" -message "The contents of the message."

Although this is a command line utility in order to be recognised by Mac OS and take the icon it needs to be bundled as an app. The icon that appears in the notification is always taken from the app, this if you want a custom icon then you have two options:

  • use the icon from another app using the -sender command
  • re compile the application with a custom icon

As I want a custom icon both require an apple icns icon file to be created. Since OS 10.8 icons contain icons of up to 1024×1024 (actually 512×512@2x for retina high DPI displays). As for the favicon and IOS bookmark icon for this site I though I would use a fleuron. Ideally I would fire up illustrator and create an nice set of icons with a subtle colour gradient. Unfortunatly as I don’t have access to Illustrator at the moment so I had to make to with powerpoint. The process was as follows:

  1. Create an empty slide in powerpoint with a white background
  2. Change the dimension to custom in page setup and set height and width to 10 cm
  3. create a text box with a single red fleuron and set the type size to fill the whole canvas with a small white border.
  4. Save as Picture, and set size to 1024×1024 in the options and save as a PNG file called icon_raw.png
  5. Open the file in Preview, and show the edit toolbar
  6. select the instant alpha tool and drag over the white region to become the alpha chanel and delete. Repeat this step for any other background regions.
  7. save as icon_1024x1024.png

In order to create the icns file the icon is needed in multple sizes, as this is a simple shape these can easily be created by adjusting the size in preview and saving as the appropriate file. Note this is not how you should create high DPI icons.

  • save icon_1024x1024.png as icon_512x512@2x.png
  • resize icon_1024x1024 to 512×512 and save as icon_512x512.png and icon_256x256@2x.png
  • resize icon_1024x1024 to 256×256 and save as icon_256x256.png and icon_128x128@2x.png
  • resize icon_1024x1024 to 128×128 and save as icon_128x128.png
  • resize icon_1024x1024 to 64×64 and save as icon_32x32@2x.png
  • resize icon_1024x1024 to 32×32 and save as icon_32x32.png and icon_16x16@2x.png
  • resize icon_1024x1024 to 16×16 and save as icon_16x16.png

Place all the png files except icon_raw.png into one folder and rename the folder icon.iconset then run
iconutil -c icns icon.iconset

If you just want to mod an icon it is worth noting that iconutil can also work in reverse and create the icon set folder and individual images from a single icns file:
iconutil -c iconset icon.icns

If you always just want to scale the original image then you can just use this online tool or the stand alone app.

Now you have your custom icns file all you need to do is edit the Xcode project:

  1. Download the source for terminal-notifier
  2. Add the icon icns file to the project
  3. Drag the icon to the App Icon under the General tab of the project replacing the current Terminal.icns App Icon
  4. Build

Move the app bundle to the Applications folder and test with the following command:

I found this command line tool called terminal-notification which sends notification to the systems:
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Custom Icon Test" -message "This icon replaced the default icon."

It might be easier to just create a small app bundle that does nothing but has an ID and a custom icon and use the -sender flag. This way you don’t need to mod terminal notifier each time there is an update.