Determine and Use Resolution as a Variable in UNIX script on Mac I'm deploying a NetRestore image to multiple kinds of Macs: MacBooks, MacBook Pros, Mac Pros, iMacs and Mac Minis. I have several custom designed login screens that I'd like to use but everything before 10.10 requires that you know the monitor resolution otherwise the login background won't show correctly.

Is there a way to use the output of this code as a variable for a series of IF/THEN statements?

system_profiler SPDisplaysDataType |grep Resolution


The normal output shows like this

  Resolution: 2560 x 1440
  Resolution: 1920 x 1200
  Resolution: 1920 x 1200


(This is if you have three monitors...I'd prefer to use the first result). 

My intention is for the script to run when binding the Mac to Active Directory (which has to be done manually), so the resolution should already be available. It would select the correct resolution image and then copy it into the required location. 

Or by chance does anyone have any good idea on how to create custom login window backgrounds and user backgrounds to work on any type of Mac with any resolution? (Just like the OS does when you select "Fit to Screen" in System Preferences)

Thanks!
If you are looking for something to put into a shell script, you can run something like

if [[ $(system_profiler SPDisplaysDataType |
             grep Resolution |
             head -1 |
             tr -d ' ') == 'Resolution:2560x1440' ]]; then
    # do whatever is needed to do for 2560x1440
end if


You could also use a case statement to handle several resolutions

case  $(system_profiler SPDisplaysDataType |
            grep Resolution |
            head -1 |
            tr -d ' ') in
    Resolution:2560x1440)
        # handle 2560x1440
        ...
        ;;
    Resolution:1920x1200)
        # handle 1920x1200
        ...
        ;;
esac