JamfHelper > dynamic icon display

dpertschi
Valued Contributor

So I thought it would be good fun if my jamfhelper script would display an icon of the specific Mac model on which the script was running. There are a bunch of places in the OS where these icons are stored, but I’m hitting a brick wall trying to figure out how best to find the one for that given machine.

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources has a good collection of icons, but will take quite a bit of work to identify model in use and then associate to correct icon there.

About This Mac > Support, that dialog box seems to consistently display the machine specific icon I want, but how do we find that resource?

5 REPLIES 5

stevevalle
Contributor III

@dpertschi This might give you a place to start!

You can get the computer model from the system_profiler command in terminal. Then change the icon using an if statement. There may be a better way of doing it, but this is what I would do!

#!/bin/sh

# Get computer model
model=$(system_profiler SPHardwareDataType | grep 'Model Identifier' | awk '{print $NF}')

# Set icon based on Model
if [[ $model == MacBook* ]]

    then
    icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.macbookpro-15-retina-display.icns"

    elif [[ $model == iMac* ]]

    then
    icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.imac-unibody-27.icns"

    else
    icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.imac-unibody-27.icns"

fi

# Run JAMFHelper
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Heading goes here!" -description "Description goes in here" -icon $icon &

exit 0

dpertschi
Valued Contributor

Thanks @stevevalle , I was thinking similarly at first and would need to add a few more conditions for MacPro's; but as a personal nit-pick I probably wouldn't want the 15" rMBP icon coming up if I was running a new space gray TB MBP.

But, as a last resort I could use the full model identifier to point to the appropriate icon in that folder. Work! Gotta be an easier way though...

mm2270
Legendary Contributor III

I'm not sure there's an actual easy way, outside of some special process that Apple may be using to determine the correct icon for the model. Since I have no insight into how Apple is doing it, I can only offer something along the lines of what @stevevalle posted, but more more involved, yet more accurate. If you really want to make sure the correct icon is showing up in the dialog, it's going to take a lot of work to make that happen.

Here's an example script that gets the icons for various MacBook Pro, MacBook Air and MacBook models from around the 2010 versions and up. It gets the model identifier and determines the correct icon in a case statement. For this exercise, an if/then block is going to make you crazy, so a case statement will be easier to manage. Note that the case statement can accept multiple identifier strings all in one block, separated by vertical pipes. This is the advantage it gives you over an if/then statement. So we can group all identifiers for, say, all the 13" MacBook Pro Retinas into one line and have it assign the correct icon for any of them that show up.

#!/bin/bash

jhPath="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

ModelIdentifier=$(sysctl hw.model | cut -d' ' -f2)


rsrcPath="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/"

case $ModelIdentifier in
    ## Model Identifiers for all 13" unibody MBPs from 2010 and up
    MacBookPro7,1|MacBookPro8,1|MacBookPro9,2)
        icon="com.apple.macbookpro-13-unibody.icns" ;;

    ## Model Identifiers for all 15" unibody MBPs from 2010 and up
    MacBookPro6,2|MacBookPro8,2|MacBookPro9,1)
        icon="com.apple.macbookpro-15-unibody.icns" ;;

    ## Model Identifiers for all 17" unibody MBPs from 2010 and up
    MacBookPro6,1|MacBookPro8,3)
        icon="com.apple.macbookpro-17-unibody.icns" ;;

    ## Model Identifiers for all 13" Retina MBPs
    MacBookPro10,2|MacBookPro11,1|MacBookPro12,1)
        icon="com.apple.macbookpro-13-retina-display.icns" ;;

    ## Model Identifiers for all 15" Retina MBPs
    MacBookPro10,1|MacBookPro11,2|MacBookPro11,3|MacBookPro11,4|MacBookPro11,5)
        icon="com.apple.macbookpro-15-retina-display.icns" ;;

    ## Model Identifiers for all 11" MBAs from 2010 to current
    MacBookAir3,1|MacBookAir4,1|MacBookAir5,1|MacBookAir6,1|MacBookAir6,1|MacBookAir7,1)
        icon="com.apple.macbookair-11-unibody.icns" ;;

    ## Model Identifiers for all 13" MBAs from 2010 to current
    MacBookAir3,2|MacBookAir4,2|MacBookAir5,2|MacBookAir6,2|MacBookAir7,2)
        icon="com.apple.macbookair-13-unibody.icns" ;;

    ## Model Identifiers for MacBooks (2010 model)
    MacBook7,1)
        icon="com.apple.macbook-unibody-plastic.icns" ;;

    ## Model Identifiers for 2015 MacBooks
    MacBook8,1)
        icon="com.apple.macbook-12-retina-display.icns" ;;

    *)
        icon="com.apple.macbook-unibody.icns" ;;
esac

fullIcon="${rsrcPath}${icon}"

"$jhPath" -windowType utility 
    -title "Some title goes here" 
    -heading "Some heading goes here" 
    -description "Some longer description goes here" 
    -icon "$fullIcon" 
    -iconSize 128 
    -button1 Ok 
    -defaultButton 1

Here's an example of the dialog when run on my Mac (a 13" Retina model)

369656abcf734c2d941627bc01918f87

If I change the model identifier by hardcoding in something for a MacBook Air 11", this is what it produces

def12456fad4402590b702622a8e49b6

If you want to include additional Mac types, like iMacs, Mac minis, Mac Pros, etc, then you will need to add to the above script. I used MacTracker to determine the model identifiers for all the different sizes, since I obviously don't have all those Macs in front of me! Feel free to expand on it.

Hope that helps.

dpertschi
Valued Contributor

@mm2270 yeah a few pages of if/then hell is not worth it for me. What you've got there is interesting though, not something I was aware of so thanks for sharing, that might work out.

Gonna keep looking for the resource that About this Mac > Support panel shows.

mm2270
Legendary Contributor III

Good luck. Certainly post back if you figure out what it's doing to get the correct icon, since I'd be interested in knowing that myself. It might end being something similar to what I show above, but done in a different language of course.

I do know that, at least the very first time it's opened, the About this Mac window makes a call to Apple's site to get the full model name. Not the identifier, but the one that would show something like "MacBook Pro (Retina, 13-inch, Early 2015)" Whether it also does some query to get the machine icon path I'm not sure though.