System Information script

dvaturi
New Contributor

Hey guys,
i was trying to upload "System information" policy to self service using the following script.
the problem is that at the end of it, while pressing on "button 2" - "Screenshot" the information box is being closed and the screenshot is being taken, this means the screenshot miss the important part, which is the information box.
how can i delay the process in few seconds so the "System information" box won't disappear before screenshot is being taken

thanks in advance,
Dean Vaturi

!/bin/sh

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

USERNAME=$(ls -l /dev/console | awk '{print $3}')
MACNAME=$(scutil --get ComputerName)
PORT=$(/usr/sbin/netstat -rn -f inet | awk '/default/{print $NF; exit}')
IPADDRESS=$(ipconfig getifaddr $PORT)
MACADDRESS=$(networksetup -getmacaddress $PORT | awk '{print $3}')

MESSAGE="You are logged in as: $USERNAME
Computer name: $MACNAME
IP Address: $IPADDRESS
MAC Address: $MACADDRESS"

THEMESSAGE=$("$JHELPER" -windowType utility -title "Palo Alto Networks System Information" -description "$MESSAGE" -button1 "OK" -button2 "Screenshot" -defaultButton 1 -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericNetworkIcon.icns" -iconSize 64)

if [ "$THEMESSAGE" == "0" ]; then exit 0
elif [ "$THEMESSAGE" == "2" ]; then DATE=$(date +"%Y-%m-%d at%l.%M.%S %p") screencapture -t png "/Users/$USERNAME/Desktop/Screen Shot ${DATE}.png" chown ${USERNAME}:staff "/Users/$USERNAME/Desktop/Screen Shot ${DATE}.png" exit 0
fi

9 REPLIES 9

Asnyder
Contributor III
sleep numberofseconds

mm2270
Legendary Contributor III

I don't think just adding in a sleep will do much good. The code won't run until the button gets clicked by the user, which in turn dismisses the dialog. So if anything, adding in a sleep value would make matters worse, not better, I think.

This is a tricky problem since, as I said, the screencapture won't get activated until after the button is clicked that calls the action into play.

I would consider a different approach here. Consider sending the data that gets generate for the dialog into a local text file with an echo or printf command, then when the button is clicked by the user, either reveal the file itself, or cat the contents of the file and send it into the clipboard for them to paste into something else.

The first one would be done something like

open /path/to/file.txt

The second one would be along the lines of

cat /path/to/file.txt | pbcopy

Last thing is, consider surrounding your script with the script quotes so it formats correctly here. You can do that with the button in the toolbar above the post editing window - >_ - or just by adding 3 tick marks, like ``` above and below the script.

Look
Valued Contributor III

Are you simply trying to display the information to the user?
I made something, never even bothered with a dialogue, just gathered the info into a text file and then opened the txt file in the default browser, they can then save this, copy from or whatever as they feel fit.
I guess if you wanted to get real fancy you could drop some proper HTML around it to.

mm2270
Legendary Contributor III

Or even better, I have something I coded and use on my Mac (have not distributed to other systems yet) that automatically generates a small formatted html file in /Users/Shared/ that contains several items, like hostname, computer name, serial #, IP address, SSID, uptime, etc. Then I have a Self Service URL based plug-in that just loads that page. It even has the company logo embedded in it at the top, so it looks semi-official. The page gets generated by a LaunchAgent triggered on network state change, so each time it triggers, it overwrites the local html file with updated info, keeping it pretty current.

Look
Valued Contributor III

@mm2270 Quite a nice idea, the plugin is just referencing the local file system then?
I would have the information generated by a weekly or daily JSS policy personally, but only because I like to try and keep as much as possible inside Casper.

mm2270
Legendary Contributor III

@Look Yes, the plug-in is simply loading the local html file that gets generated and placed in /Users/Shared/ And yes, you could of course just have a policy that runs every so often and updates the html file. Of course, if you do that, then information like IP address and some other details would need to be excluded since it won't really be relevant if it's not updating that file more frequently. But other system related info that doesn't change that often could be put in there.

dvaturi
New Contributor

please share your thoughts and scripts i might change my method..
its always nice to learn new things,
thanks in advance

GregE
Contributor

Has anyone used a Computer Information script packaged as an Application? Thanks to @dvaturi for his excellent script, I've added a few of my own lines for some extra information (what OS a user is on for example).
I want to have this on the users desktop rather run it via Self Service. I've used Automator to create an App using the Shell Script function and have put a nice logo on the App so it all looks great, then created a DMG of it with Jamf Composer which is deployed via Policy.

All that works great when I test it on my own Mac, but as soon as I push it out (during login) to a "Standard User Account" student iMac for example, the App isn't deployed properly in to the folder I've put it. It shows as Zero KB with a circle & cross through it.
If you log in as an admin when it's deployed, it's fine, if you log in as a standard user when it's deployed - Zero KB app.

I've tried 744, 666 and various permission combinations when creating the DMG but without success so far. Wondering what other people do?

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

USERNAME=$(ls -l /dev/console | awk '{print $3}')
MACNAME=$(scutil --get ComputerName)
PORT=$(/usr/sbin/netstat -rn -f inet | awk '/default/{print $NF; exit}')
IPADDRESS=$(ipconfig getifaddr $PORT)
MACADDRESS=$(networksetup -getmacaddress $PORT | awk '{print $3}')
OSXVERSION=$(/usr/bin/defaults read "$3/System/Library/CoreServices/SystemVersion" ProductVersion)
MODEL=$(ioreg -l | awk '/product-name/ { split($0, line, """); printf("%s ", line[4]); }')
Serial=$(ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, """); printf("%s ", line[4]); }')

MESSAGE="You are logged in as: $USERNAME
Computer name: $MACNAME
IP Address: $IPADDRESS
MAC Address: $MACADDRESS
OS X Version: $OSXVERSION
Model: $MODEL
Serial: $SERIAL"

THEMESSAGE=$("$JHELPER" -windowType utility -title "System Information" -description "$MESSAGE" -button1 "OK" -button2 "Screenshot" -defaultButton 1 -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericNetworkIcon.icns" -iconSize 64)

if [ "$THEMESSAGE" == "0" ]; then exit 0
elif [ "$THEMESSAGE" == "2" ]; then DATE=$(date +"%Y-%m-%d at%l.%M.%S %p") screencapture -t png "/Users/$USERNAME/Desktop/Screen Shot ${DATE}.png" chown ${USERNAME}:staff "/Users/$USERNAME/Desktop/Screen Shot ${DATE}.png" exit 0
fi

GregE
Contributor

Solved the above by packaging/creating it in a 'non admin' user profile on my Mac.