Posted on 09-23-2015 03:25 PM
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?"'
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
Posted on 09-23-2015 03:27 PM
I guess my subject line dropped the "System Events popup?".... -_-
Posted on 09-23-2015 04:02 PM
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.
Posted on 09-23-2015 04:57 PM
haha probably not a bad idea... Ill look into it! thanks :)
Posted on 09-24-2015 06:16 AM
I second the suggestion to look at cocoaDialog. Its much more flexible than most other dialoging utilities out there.
Its pluses are:
Its minuses are:
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.
Posted on 09-24-2015 07:28 AM
@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!
Posted on 09-24-2015 07:31 AM
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.
Posted on 09-24-2015 07:58 AM
Admittedly I haven't played around with it. I put in sudo jamf displayMessage -message Yo
and got this.
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.
Posted on 09-24-2015 08:04 AM
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.
Posted on 09-24-2015 08:12 AM
Ahh, thanks for that @mm2270 ! See, this is why we should listen to him!
Posted on 09-25-2015 04:27 AM
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!