Huh, so that script ALSO shows the dialog twice from SS? That's pretty odd, since its the same issue reported with the other scripts. That's got to be a bug in Self Service I think because there's no reason for it to do that.
As for documentation, the stuff up on the github page is very out of date. To view more current info (albeit no real descriptions of them) do something like...
/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog mgbox --help
…to see all the available flags for that window type. Just change the window type from msgbox to whatever else you want to view relevant info for, like progressbar, etc.
Not familiar with cocoaDialog - is this an application that would need to be installed on all our Mac clients before this script would work?
Yes, its a very flexible (albeit getting old) windowing utility. It allows for everything from simple dialogs, file selection windows (like when you use the :Open" command in an application), progress bars that can move with real progress and several other modes.
Get the last beta release from here:
http://mstratman.github.io/cocoadialog/
Choose the Download below the cocoaDialog (development) section. You can read up on it at that same location. Keep in mind that the documentation is mostly written for the older 2.x release, not the 3.x beta, which most of us here are using. The docs haven';t really been updated in some time, nor has the utility itself.
You can package it up to whatever location you want, like /Applications/Utilities/ or wherever and push it with a policy to your Macs. We place ours in /Library/Application Support/JAMF/bin/
Do a search here on JN for "cocoadialog" and you will likely pull up dozens of threads that cover its usage and plenty of existing script examples to get you started.
Here's a slightly updated version that I haven't thoroughly tested, but should display the word (Default) after the IP with the service that is listed first in the service order, meaning its the default interface for net connection, even when there are multiple ones active.
So for example if someone has 2 active NICs, Ethernet and Wi-Fi and they've reordered their interfaces to make Wi-Fi the default even when Ethernet is active, it will display this (hopefully) in the dialog. I tested it with my iPhone USB connection and both Ethernet (built-in) and USB Ethernet on different Macs after switching the service order around in System Preferences > Network and it always displays the Default one as the service that was listed at the top in the Network Pref Pane.
I also changed it to use "unset IFS" instead of explicitly setting IFS to a space since that's the safer way to do it.
Let me know if it doesn't work or displays anything odd.
#!/bin/bash
## Name: show-my-ips.sh
## Path to cocoaDialog. Customize to your environment
cdPath="/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog"
## Get the Mac's name
MACNAME=$(scutil --get ComputerName)
IFS=""
## Place all hardware ports into array
while read port; do
HWPORTS+=( "$port" )
done < <(echo $(networksetup -listallhardwareports | awk -F': ' '/Hardware Port/{ print $NF }'))
## Place all device ids into array
while read device; do
DEVICES+=( "$device" )
done < <(echo $(networksetup -listallhardwareports | awk '/Device/{ print $NF }'))
## Get the default interface ID
DEFAULT=$(/usr/sbin/netstat -rn -f inet | awk '/default/{print $NF; exit}')
## Loop over hardwareport array checking for active IP and add any to new array along with device IDs
for ((i = 0; i < ${#HWPORTS[@]}; i++)); do
IP=$(ipconfig getifaddr ${DEVICES[$i]})
if [[ ! -z "$IP" ]]; then
if [[ "${DEFAULT}" == "${DEVICES[$i]}" ]]; then
IPADDRESSES+=("${HWPORTS[$i]} (${DEVICES[$i]}): ${IP} (Default)
")
else
IPADDRESSES+=("${HWPORTS[$i]} (${DEVICES[$i]}): ${IP}
")
fi
fi
done
## Reset IFS to space
unset IFS
## Clean up final array for message
ACTIVEIPS=$(echo -e "${IPADDRESSES[@]}" | sed 's/^ *//')
MESSAGE="The following are details about your computer:
Mac Name:
${MACNAME}
Device Name (Port): IP Address:
${ACTIVEIPS[@]}"
"$cdPath" msgbox
--title "My IP Addresses"
--text "Details about your Mac"
--informative-text "$MESSAGE"
--button1 " OK "
--icon network
--quiet
@PeterG I modified your script to include Ethernet 1 and Ethernet 2 ports, for accurate reporting on Mac Pros. Tested and confirmed working on a Late 2013 "trash can" Mac Pro.
#! /bin/bash
# Name: MyIP.sh
# Version: 1.0
# Author: Peter Gawlocki
SUBonTB=`networksetup -getinfo Thunderbolt Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonDTB=`networksetup -getinfo Display Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonWiFi=`networksetup -getinfo Wi-Fi|grep Subnet| wc |awk '{print $1}'`
SUBonEnet=`networksetup -getinfo Ethernet|grep Subnet| wc |awk '{print $1}'`
SUBonEnet1=`networksetup -getinfo Ethernet 1|grep Subnet| wc |awk '{print $1}'`
SUBonEnet2=`networksetup -getinfo Ethernet 2|grep Subnet| wc |awk '{print $1}'`
if [ $SUBonEnet = 1 ]
then
ReportEnetAddress=`networksetup getinfo Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportEnetAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonEnet1 = 1 ]
then
ReportEnetAddress=`networksetup getinfo Ethernet 1|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet 1 is: "$ReportEnetAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonEnet2 = 1 ]
then
ReportEnetAddress=`networksetup getinfo Ethernet 2|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet 2 is: "$ReportEnetAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonWiFi = 1 ]; then
ReportWiFiAddress=`networksetup getinfo Wi-Fi|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Wireless is: "$ReportWiFiAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonTB = 1 ]; then
ReportTBENAddress=`networksetup getinfo Thunderbolt Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Ethernet is: "$ReportTBENAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
if [ $SUBonDTB = 1 ]; then
ReportTBENAddress=`networksetup getinfo Display Ethernet|grep IP| awk '{print $3}'`
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/Network.icns -title "Your IP Address" -description "Your current IP address for Display Ethernet is: "$ReportTBENAddress -button1 "Ok" -cancelButton 1 -timeout 10;
fi
You could also use GeekTool with the following script:
wifiOrAirport=$(/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)')
wirelessDevice=$(/usr/sbin/networksetup -listallhardwareports | awk "/$wifiOrAirport/,/Device/" | awk 'NR==2' | cut -d " " -f 2)
wirelessIP=$(ipconfig getifaddr $wirelessDevice)
wiredDevice=$(networksetup -listallhardwareports | grep -A 1 "Port: Ethernet" | sed -n 's/Device/&/p' | awk '{print $2}')
wiredIP=$(ipconfig getifaddr $wiredDevice)
echo "Wireless IP: $wirelessIP"
echo "Wired IP: $wiredIP"
external image link
Applescript can do that as well. I just did this as a quick and dirty POC. I am sure you can add/change things to this.
osascript -e 'display notification "Casper Time!" with title "Stop"'
external image link
@tlarkin
Casper's working so hard
Makes me say oh my lord
thank you for blessing me
with superior manageability
It feels good to push profiles down
a super dope framework for Appletown
Keeps our Macs in line with scripts and such
'cause Casper is a suite - you can't touch
@znilsson
That just made my day, I laughed at that pretty hard.
Thanks for that
-Tom
@ jhbush1973
Anyway to add computer name to that script as well?
I really love MonkeyBread's IPInMenuBar along with a launchagent...
Unfortunately, we cannot pushout freeware to our clients
@mm2270 I've added your script mentioned above (7/2014) and made it available via Self Service.
After updating to Casper Suite 9.82, systems with 10.11.2 will run the script, but then the following error appears after clicking OK on the dialog box:
Self Service: Cannot Install Item There was a problem installing Show IP. Contact your administrator.
I haven't dug into it yet. Not sure if it's an issue with Self Service 9.82.
UPDATE: Error appears on devices with 10.10.5. I wonder if it is a change in the error handling introduced with 9.82? Still digging into it...
@jhalvorson When I get a chance I will run the script against a 10.11.2 Mac to see what the issue may be, but at the moment, we aren't on Casper Suite 9.82 yet, so I won't know if its a specific issue with 9.82 or with OS X 10.11.x. It could be the OS and not Casper. This is an older thread, long before El Capitan was released, so none of these scripts were designed with El Cap in mind.
Here is the error that would take place when running a script from Self Service. The script was called "Show IP" and did not include an exit command.

I suspect it might be related to how Casper Suite 9.82 handles error codes or when there is no exit.
I added an exit 0 to the end of the script to fix the issue.
exit 0
Wondering if anyone ever discovered a way to do this with OS versions after Yosemite and via Self Service versions after v9.82. Specifically we are now on Self Service v9.96 and have El Capitan 10.11.6 and Sierra 10.12.0 in production. The script variations above that were successful always generated the error shown immediately above in OS versions post-Yosemite. Third party solutions to present this information are not an option in our environment. The "Show additional information in the menu bar" setting for Login Window through Configuration Profiles goes a long way toward resolving this, however requires the active user to log out.

Ideally, we would also have a Self Service based means of displaying the node name and IP Address(es) to the end-user while allowing them to remain logged in. Most users are not particularly savvy at locating this quickly and they are routinely asked for the info by a rotating staff of Service Desk technicians that may or may not know how to provide instructions for its retrieval from the login window menubar. Thoughts?
Ive updated one of the scripts above so it works with MacOS Sierra. And also made it look a little more professional with a little icon next to the information.
#!/bin/bash
# dispaly information to end user
# set IFS for new line
# use unset IFS to reset it to default value
IFS=$'
'
## Setting up services to display
## Get the Mac's name
MACNAME=$(scutil --get ComputerName)
#Get list of networkservices exlcuding disabled services
NetServices=$(networksetup -listallnetworkservices | grep -v '*')
for service in ${NetServices} ; do
echo "${service}: $(networksetup -getinfo ${service} | awk '/IP address:/ { gsub("[a-z]", ""); print $3 }' | sed 's/://g')" >> /tmp/netinfo.txt
done
#Applescript to display dialog
osascript <<AppleScript
tell application "Finder"
activate
set ComputerNameInfo to "Machine Name: $MACNAME" & "
$(cat /tmp/netinfo.txt)"
display alert "Your computer informaton is:" message ComputerNameInfo
end tell
AppleScript
unset IFS
#Clean up temp file created
rm -rf /tmp/netinfo.txt
exit 0
Have to say, lust like others i am starting to go a bit stirr crazy with our service desk and users not log proper information cause they just freeze when the user says its a mac.
so dont want to clutter up menu bar as we have already done that with all our drivers and utilities, and logon window only being asscesable when logged off. what apps could 'Write' on the desktop
apart from the BGINFORX whcih im not very imprested with and Geektool which is almost overkill what else can do it?