Posted on 06-18-2013 09:35 AM
CocoaDialog gurus.. can you please help?
I wish to have a window with an indeterminate progress bar that's text fields are updated with the output of the jamf binary (in this case the output of jamf installAllCached & sudo jamf recon)..
I'm just struggling a little & am sure someone else has done this.. please advise.
(oh i'm using v3-beta7 btw)
Solved! Go to Solution.
Posted on 06-18-2013 09:47 AM
Yeah, it seems really complicated at first glance, but its actually pretty simple once you've created a few. Its just a matter of setting up a file descriptor that you assign to the progress bar, then echo the information into the file descriptor and the progress bar reads that back and updates its text accordingly.
Honestly the trickier part when I was making some of this stuff was figuring out how to get the info from the lines of stdout that I wanted and excluding the rest. A little experimenting with grep and awk/cut usually sorts most of that out though,
Edit: Also, one thing I've seen some people get confused about with cocoaDialog. Even if just using an "indeterminate" progress bar, the KEY is to make sure the first part of the echoed line is a number. Follow that up with whatever information you grepped out from the process you're running. That tells the progress bar to update its text line. Without that digit up front it will ignore everything else after it and remain with the initial text you set it up with during the whole run.
Posted on 06-18-2013 10:15 AM
Ben, that's all good except the most important line at the end. Try something like this instead-
sudo jamf recon 2>&1 | while read line; do
echo "10 $line" >&3
done
Each line of the recon process gets read and is echoed back to the file descriptor 3 along with a number as the first part of your echoed line, which tells cocoaDialog to use the text immediately after the number as the string to use to update the progress bar text.
Make sense?
Mike
Posted on 06-18-2013 09:39 AM
@Ben, take a look at my posts on this Feature Request. You should be able to use what I posted there to adapt it to your needs-
https://jamfnation.jamfsoftware.com/featureRequest.html?id=1148
Posted on 06-18-2013 09:41 AM
Thanks Mike!
Looks like i'll need to get my head around pipes then? with iHook you can just echo it out..
Posted on 06-18-2013 09:47 AM
Yeah, it seems really complicated at first glance, but its actually pretty simple once you've created a few. Its just a matter of setting up a file descriptor that you assign to the progress bar, then echo the information into the file descriptor and the progress bar reads that back and updates its text accordingly.
Honestly the trickier part when I was making some of this stuff was figuring out how to get the info from the lines of stdout that I wanted and excluding the rest. A little experimenting with grep and awk/cut usually sorts most of that out though,
Edit: Also, one thing I've seen some people get confused about with cocoaDialog. Even if just using an "indeterminate" progress bar, the KEY is to make sure the first part of the echoed line is a number. Follow that up with whatever information you grepped out from the process you're running. That tells the progress bar to update its text line. Without that digit up front it will ignore everything else after it and remain with the initial text you set it up with during the whole run.
Posted on 06-18-2013 09:59 AM
Thanks.. still a little confused though.. what am i missing?
#!/bin/sh
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
sleep 0.2
/usr/local/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog progressbar --indeterminate --title "Updates are currently being installed, please do not turn off this computer" --icon "installer" --text "Updates are installing..." < /tmp/hpipe &
exec 3<> /tmp/hpipe
sudo jamf recon >&3
Basically, even though the below works using iHook.. i'd like to simplify it using one app.. & am getting a little confused on the way!
Posted on 06-18-2013 10:15 AM
Ben, that's all good except the most important line at the end. Try something like this instead-
sudo jamf recon 2>&1 | while read line; do
echo "10 $line" >&3
done
Each line of the recon process gets read and is echoed back to the file descriptor 3 along with a number as the first part of your echoed line, which tells cocoaDialog to use the text immediately after the number as the string to use to update the progress bar text.
Make sense?
Mike
Posted on 06-18-2013 01:24 PM
Thanks Mike! The below works..
#!/bin/sh
# Check to see if dummy receipt exists
if [ -f /.jssUpdates-Cached ]; then
# Remove temp pipe file if exists
rm -f /tmp/cdupdatepipe
# Create temp pipe file
mkfifo /tmp/cdupdatepipe
sleep 0.2
# Start cocoaDialog prompt
/usr/local/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog progressbar --indeterminate --title "Updates Are Being Installed, Please Do Not Power Off" --height "128" --width "500" --icon "installer" --icon-height "96" --icon-width "96" --float < /tmp/cdupdatepipe &
# Echo out to pipe to be relayed to cocoaDialog window
exec 3<> /tmp/cdupdatepipe
# Install all jamf cached updates, echoing out to cocoaDialog prompt
sudo jamf installAllCached 2>&1 | while read line; do
echo "10 $line" >&3
done
# Remove dummy receipt
rm -rf /.jssUpdates-Cached
sudo jamf recon 2>&1 | while read line; do
echo "10 $line" >&3
done
else
echo "No dummy receipt found.. Exiting..."
exit 0
fi
Now if only the recon didn't take so long.. oh wait.. I submitted a FR for that yonks ago!
https://jamfnation.jamfsoftware.com/featureRequest.html?id=78
Posted on 06-18-2013 02:27 PM
Cool! Glad that worked. Once you start to use this method, you may, like me, start thinking about all kinds of output from scripts, policies, installations and whatever else that you can send to it. It can be pretty useful.
As for the recon part, I actually am testing something that runs recon as a background process after any installation, even ones that aren't initiated by a Casper Suite policy. So for example if a user installs software on their own, it detects this and recons the Mac shortly after its done. So far in testing it seems to be working, but I need to keep playing with it. Cool thing about it is, if all goes well, we can, (in theory!) uncheck the "Update Inventory" box in all Self Service policies, since that recon piece is generally the item that makes the whole dang thing "feel" so slow.
Its no replacement for your FR though, Still want to be able to limit an inventory to only certain items/verbs. I'm praying JAMF adds this into version 9.
Posted on 04-05-2014 10:43 AM
@mm2270][/url just wanted to say thanks for this as it also helped me work on my own first experiment with using the progressbar. I'll post what I have here as another example of using the progressbar so that it can help others:
#!/bin/bash
# Set cocoaDialog location
CD="/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Make pipe
/bin/rm -f /tmp/hpipe
/usr/bin/mkfifo /tmp/hpipe
/bin/sleep 0.2
# Background job to take pipe input
"$CD" progressbar --indeterminate --title "Executing Policies" --text "Please wait..." --icon "gear" --float < /tmp/hpipe &
# Link file descriptor
exec 3<> /tmp/hpipe
# Run everyHour policies
EVERYHOUR=$(/usr/bin/pgrep -f "jamf policy -action everyHour -randomDelaySeconds 2700")
if [[ $EVERYHOUR -eq "0" ]];
then
/bin/echo "everyHour not running"
/usr/sbin/jamf policy -trigger everyHour 2>&1 | while read line; do
/bin/echo "10 $line" >&3
done
else
/bin/echo "Killing everyHour process"
/bin/kill $EVERYHOUR
/usr/sbin/jamf policy -trigger everyHour 2>&1 | while read line; do
/bin/echo "10 $line" >&3
done
fi
# Let processes catch up
/usr/bin/wait
# Remove pipe
/bin/rm -f /tmp/hpipe
exit 0