displayMessage line break.

danny_hanes
Contributor

Is there anyway to have a multi-line message? I am trying to have a user click on a button in self service and display things like computer name / username / mac address / IP address for our service desk staff and I can get one line to show but no more. Really don't want them to have to click multiple self service buttons.

1 ACCEPTED SOLUTION

rlandgraf
Contributor

This is the script that I use for this, you may need to edit it if you have a bunch of newer machines that only have wireless.

#!/bin/sh

#en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
en1Status=`ifconfig en1 | tr ' ' '
' | grep "active"`
en0Status=`ifconfig en0 | tr ' ' '
' | grep "active"`
CurrentUser=`who | grep "console" | awk '{print $1}'`
hostnamename=`hostname | cut -d "." -f 1`
computername=`jamf getComputerName | cut -d ">" -f2 | cut -d "<" -f1`
OSVersion=`sw_vers | grep "ProductVersion" | awk '{print $2}'`
en1MACAddress=`ifconfig en1 | grep "ether" | cut -d" " -f2`
en0MACAddress=`ifconfig en0 | grep "ether" | cut -d" " -f2`
TotalRam=`system_profiler SPHardwareDataType | grep "Memory:" | cut -d":" -f2`
BootVolume=`system_profiler SPSoftwareDataType | grep "Boot Volume:" | cut -d":" -f2`

TotalBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Capacity:" | cut -d ":" -f2 | cut -d "(" -f1`
AvailBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Available:" | cut -d ":" -f2 | cut -d "(" -f1`

if [ "$en1Status" == "active" ];
    then en1Address=`ifconfig en1 | grep "inet " | cut -d " " -f2`
    else en1Address="not active"
fi

if [ "$en0Status" == "active" ];
    then en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
    else en0Address="not active"
fi



jamf displayMessage -message "Wired address is $en0Address 
Wireless address is $en1Address
Current Logged on user is $CurrentUser
Computer name is $computername
Hostname is $hostnamename
OS version is $OSVersion
Wired MAC Address is $en0MACAddress
Wireless MAC Address is $en1MACAddress
Total RAM (Memory):$TotalRam
Boot Volume:$BootVolume
    Total size:$TotalBootDriveSize
    Free space:$AvailBootDriveSize"

View solution in original post

10 REPLIES 10

rlandgraf
Contributor

This is the script that I use for this, you may need to edit it if you have a bunch of newer machines that only have wireless.

#!/bin/sh

#en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
en1Status=`ifconfig en1 | tr ' ' '
' | grep "active"`
en0Status=`ifconfig en0 | tr ' ' '
' | grep "active"`
CurrentUser=`who | grep "console" | awk '{print $1}'`
hostnamename=`hostname | cut -d "." -f 1`
computername=`jamf getComputerName | cut -d ">" -f2 | cut -d "<" -f1`
OSVersion=`sw_vers | grep "ProductVersion" | awk '{print $2}'`
en1MACAddress=`ifconfig en1 | grep "ether" | cut -d" " -f2`
en0MACAddress=`ifconfig en0 | grep "ether" | cut -d" " -f2`
TotalRam=`system_profiler SPHardwareDataType | grep "Memory:" | cut -d":" -f2`
BootVolume=`system_profiler SPSoftwareDataType | grep "Boot Volume:" | cut -d":" -f2`

TotalBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Capacity:" | cut -d ":" -f2 | cut -d "(" -f1`
AvailBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Available:" | cut -d ":" -f2 | cut -d "(" -f1`

if [ "$en1Status" == "active" ];
    then en1Address=`ifconfig en1 | grep "inet " | cut -d " " -f2`
    else en1Address="not active"
fi

if [ "$en0Status" == "active" ];
    then en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
    else en0Address="not active"
fi



jamf displayMessage -message "Wired address is $en0Address 
Wireless address is $en1Address
Current Logged on user is $CurrentUser
Computer name is $computername
Hostname is $hostnamename
OS version is $OSVersion
Wired MAC Address is $en0MACAddress
Wireless MAC Address is $en1MACAddress
Total RAM (Memory):$TotalRam
Boot Volume:$BootVolume
    Total size:$TotalBootDriveSize
    Free space:$AvailBootDriveSize"

danny_hanes
Contributor

@rlandgraf Well that was incredibly helpful! Thanks!

emily
Valued Contributor III
Valued Contributor III

Very handy! Though I'm not getting results for the Total size and free space. Love having easy access to the MAC addresses, though.

hkabik
Valued Contributor

I also like to toss in the serial number for quick warranty status checks. Definitely not a necessary addition though.

SerialNumber=`system_profiler SPHardwareDataType | grep Serial | awk '{ print $4 }'`

jamf displayMessage -message "
Serial Number is $SerialNumber"

emily
Valued Contributor III
Valued Contributor III

Here is a cocoaDialog version:

#!/bin/sh

#en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
en1Status=`ifconfig en1 | tr ' ' '
' | grep "active"`
en0Status=`ifconfig en0 | tr ' ' '
' | grep "active"`
CurrentUser=`who | grep "console" | awk '{print $1}'`
hostnamename=`hostname | cut -d "." -f 1`
computername=`jamf getComputerName | cut -d ">" -f2 | cut -d "<" -f1`
OSVersion=`sw_vers | grep "ProductVersion" | awk '{print $2}'`
en1MACAddress=`ifconfig en1 | grep "ether" | cut -d" " -f2`
en0MACAddress=`ifconfig en0 | grep "ether" | cut -d" " -f2`
TotalRam=`system_profiler SPHardwareDataType | grep "Memory:" | cut -d":" -f2`
BootVolume=`system_profiler SPSoftwareDataType | grep "Boot Volume:" | cut -d":" -f2`

TotalBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Capacity:" | cut -d ":" -f2 | cut -d "(" -f1`
AvailBootDriveSize=`system_profiler SPSerialATADataType | grep "$BootVolume" -A2 | grep "Available:" | cut -d ":" -f2 | cut -d "(" -f1`

if [ "$en1Status" == "active" ];
then en1Address=`ifconfig en1 | grep "inet " | cut -d " " -f2`
else en1Address="not active"
fi

if [ "$en0Status" == "active" ];
then en0Address=`ifconfig en0 | grep "inet" | cut -d " " -f2`
else en0Address="not active"
fi


/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog msgbox 
--title "" --text "Your Computer Info" 
--informative-text "Wired address is $en0Address
Wireless address is $en1Address
Current Logged on user is $CurrentUser
Computer name is $computername
Hostname is $hostnamename
OS version is $OSVersion
Wired MAC Address is $en0MACAddress
Wireless MAC Address is $en1MACAddress
Total RAM (Memory):$TotalRam
Boot Volume:$BootVolume
- Total size:$TotalBootDriveSize
- Free space:$AvailBootDriveSize" --button1 "OK" --quiet

Though admittedly I'm getting mixed results on my Retina Pro hooked up to a Thunderbolt display, since the display's ethernet is apparently en7. I'm guessing the above is designed for MBP 2012 and earlier?

rlandgraf
Contributor

@emilykausalik Yeah I wrote this some time ago for machines that had ethernet and wifi as en0 and en1. The logic would have to be added in to better figure out which ports are which. We are running mostly older MacBooks here so I hadn't really needed to update.

exno
Contributor

I took this and made some changes to get it to display simplified info for my users to give us.

The only way i could get HD capacity and availability is to use SPStorageDataType but it does add the benefit of offering external drive info as well

as for the IP i am just grepping anything that is " active" in ifconfig and pulling the IP.. may be an issue if multiple IPs are on our devices but will also let us know if a user has turned on wifi somehow.

@emilykausalik My around the way method for IP should work on your MacBook Pro too

#!/bin/bash
#####
#
#A script to display info for the mac
#
#####

CurrentUser=`who | grep "console" | awk '{print $1}'`
hostnamename=`hostname | cut -d "." -f 1`
computername=`jamf getComputerName | cut -d ">" -f2 | cut -d "<" -f1`
OSVersion=`sw_vers | grep "ProductVersion" | awk '{print $2}'`
TotalRam=`system_profiler SPHardwareDataType | grep "Memory:" | cut -d":" -f2`
BootVolume=`system_profiler SPSoftwareDataType | grep "Boot Volume:" | cut -d":" -f2`
IPAddress=`ifconfig | grep " active" -B3 | grep "inet " | cut -d " " -f2`
TotalBootDriveSize=`system_profiler SPStorageDataType | grep "Capacity:" | cut -d ":" -f2 | cut -d "(" -f1`
AvailBootDriveSize=`system_profiler SPStorageDataType | grep "Available:" | cut -d ":" -f2 | cut -d "(" -f1`


jamf displayMessage -message "IP Address is $IPAddress
Current Logged on user is $CurrentUser
Computer name is $computername
Hostname is $hostnamename
OS version is $OSVersion
Total RAM (Memory):$TotalRam
Boot Volume:$BootVolume
    Total size:$TotalBootDriveSize
    Free space:$AvailBootDriveSize"
- I am @exno or @exnozero on almost everything that exists.

calumhunter
Valued Contributor

A nice way to get the active interface ie en0 or en1 or whatever and then get the IP address for it

#!/bin/bash

active_interface=`route get www.apple.com | awk '/interface/ { print $2 }'`
my_ip_address=`ipconfig getifaddr $active_interface` 

echo "My Active (Primary) interface is: ${active_interface}."
echo "My Active (Primary) IP Address is: ${my_ip_address}."

mlr
New Contributor II

I've updated to reflect info we wanted:

#!/bin/bash
#####
#
#A script to display info for the mac
#
#####

CurrentUser=`who | grep "console" | awk '{print $1}'`
hostnamename=`hostname | cut -d "." -f 1`
computername=`jamf getComputerName | cut -d ">" -f2 | cut -d "<" -f1`
OSVersion=`sw_vers | grep "ProductVersion" | awk '{print $2}'`
TotalRam=`system_profiler SPHardwareDataType | grep "Memory:" | cut -d":" -f2`
BootVolume=`system_profiler SPSoftwareDataType | grep "Boot Volume:" | cut -d":" -f2`
IPAddress=`ifconfig | grep " active" -B3 | grep "inet " | cut -d " " -f2 | tr '
' ' '`
TotalBootDriveSize=`system_profiler SPStorageDataType | grep "Capacity:" | cut -d ":" -f2 | cut -d "(" -f1`
AvailBootDriveSize=`system_profiler SPStorageDataType | grep "Available:" | cut -d ":" -f2 | cut -d "(" -f1 | head -1`
localmac=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-)
curldata=$(curl -s https://support-sp.apple.com/sp/product?cc=$localmac| sed 's|.*<configCode>(.*)</configCode>.*|1|')
ssid=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep SSID: | sed "1 d" |  cut -f2 -d$':' | cut -d ' ' -f 2)
FED2=`fdesetup status | grep is | tr -d 'FileVault is ' | tr -d '.'`
if [ "$FED2" == "" ]; then
fv="Off"
else
fv="On"
fi



jamf displayMessage -message "IP Address(es) is $IPAddress
WiFi SSID: $ssid
Current Logged on user is $CurrentUser
FileVault = $fv
Mac Model: $curldata
Hostname is $hostnamename
OS version is $OSVersion
Total RAM (Memory):$TotalRam
Boot Volume:$BootVolume
Free space:$AvailBootDriveSize"    
exit 0

burdett
Contributor II

Jamf has posted a Build a Computer Information script for your Help Desk here;
https://www.jamf.com/blog/build-a-computer-information-script-for-your-help-desk/