Custom Icon for

rmaldon
New Contributor III

Hey guys,

I have been playing around with popup dialogues and came across osascript. Im trying to figure out if there is a way to specify, replace, or use a different icon than the default one that pops up(see screenshot).

osascript -e 'tell application "System Events" to display alert "<------- Can I customize this?"'

optional image ALT text

I have terminal-notifier on the devices as well, and saw you can use bundle identifiers for that, but I was wondering if there was any stock way to do it, or maybe find some other cool ideas you guys are doing out there :)

Thanks!
Ricky

10 REPLIES 10

rmaldon
New Contributor III

I guess my subject line dropped the "System Events popup?".... -_-

nessts
Valued Contributor II

learn cocoa dialog, you will be more happier and be able to get input from users more easier :D search for cocoa dialog on jamf nation should find plenty of discussions and examples. But, you are welcome to try and get stuff done in apple script and wait for apple to change stuff every release and break what you had working.

rmaldon
New Contributor III

haha probably not a bad idea... Ill look into it! thanks :)

mm2270
Legendary Contributor III

I second the suggestion to look at cocoaDialog. Its much more flexible than most other dialoging utilities out there.
Its pluses are:

  • Can be called with almost any scripting language, so if you're more comfortable with bash or perl or whatever, you can invoke it, unlike Applescript that needs to be called using osascript (or directly in Applescript scripts).
  • Has multiple different window styles including regular dialogs, progress bars, input boxes, check boxes, radio buttons, file selection and so on.
  • Has fine controls over window size and position if you want to do that. (in the later beta 3.0 versions)
  • Easy to call a custom icon for the dialog and control the size of the icon too.

Its minuses are:

  • Its not built into the OS, so it needs to be deployed to your Macs first.
  • its old and has not been updated in over 3 years now. Miraculously still works in 10.10 and I believe in 10.11 as well, though I haven't done much testing with it yet in El Capitan.
  • Because its old, some window modes don't work too well or at all.
  • It could stop working at some point, and since the developer isn't working on it anymore, could leave it non functional with no course for fixes, unless someone else takes up the reins.

All that being said, just to answer your actual question, here is some AS code you can use to call a custom icon for a dialog. Note that not all AS windows can take an icon. An example is the "choose from list" style. You can't add an icon to those windows unfortunately. I think the file selection window also cannot use an icon.

#!/bin/sh

/usr/bin/osascript <<EOF
display dialog "This is an announcement" buttons {"OK"} default button 1 with icon file ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Actions.icns"
EOF

As you can see, you need to use the with icon file call and then include a path to the icon in Applescript style, meaning path delimiters are : instead of /
I'm also not sure of all the image formats it can accept, but I know .icns and .png work. Its possible others do as well.

Chris_Hafner
Valued Contributor II

@mm2270 is quite well versed in this sort of thing so I recommend looking into his solutions. However, you 'can' changer the icon associated with the

jamf displayMessage -message

command.

I'm trying to remember where you change the icon. @emilykausalik is usually who I would ask for advice on this!

Not applicable

cocoaDialog appears to still work on my 10.11.1 test box - at least, loceee's 'dodgy' fork does - and is a well-known, well-documented solution.

You might also want to check out Shea Craig's excellent utility, Yo, which lets you customize icons, push notifications into the Notification Center (sticky!), etc.

emily
Valued Contributor III
Valued Contributor III

Admittedly I haven't played around with it. I put in sudo jamf displayMessage -message Yo and got this.

8f4afe657ba445688eeb4c53850a3968

All I see in the help menu for this is:

:~$ jamf help displayMessage

Usage:   jamf displayMessage -message <message>

     -message        The message to be displayed.

…nothing about an icon.

The icon itself appears to be stored in /Library/Application Support/JAMF/bin/jamfHelper/Contents/Resources so logic dictates that if you can't call a specific icon you can theoretically replace it within the jamfHelper, but you'd have to redeploy the whole thing so… I'd just say use cocoaDialog.

mm2270
Legendary Contributor III

jamf displayMessage doesn't have an option take a custom icon, but jamfHelper does of course. Either use jamfHelper or cocoaDialog, or Applescript, but the caveat is that sometimes Applescript just doesn't work in the context of running it in a script from Casper.

Chris_Hafner
Valued Contributor II

Ahh, thanks for that @mm2270 ! See, this is why we should listen to him!

sean
Valued Contributor

Pahsua is an alternative that is still updated regularly. It is more configurable than cocoadialog, which makes it mildly more complex, but it is current!