CocoaDialog can be finicky and you have to use the beta of version 3 for progress to work but here is code to show progress of caching a package. I have a function for when I call the installer too if you need that. You have to tell it the size of the package since it can't be determined dynamically with the way packages ae cached currently.
cdPath="/Path/To/cocoaDialog.app/Contents/MacOS/cocoaDialog"
cdIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ApplicationsFolderIcon.icns"
cdTitle="Dialog Title"
pkgTotal=12064712
pkgPartial=0
downloadFolder="/Library/Application Support/JAMF/Downloads"
waitingRoomFolder="/Library/Application Support/JAMF/Waiting Room"
dmgName="Package.dmg"
dialogDownload()
{
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
sleep 0.2
"$cdPath" progressbar --stoppable --title "Upgrade Package Download Progress" --text "Downloading..." --float < /tmp/hpipe > /tmp/_out &
exec 3< <(yes)
exec 3<> /tmp/hpipe
if { >&3; } 2> /dev/null
then
writeLog "Pipe RW verified"
else
writeLog "Pipe RW failed"
fi
trap : SIGTERM SIGINT
echo $$
(jamf policy -event PayloadName ) > /tmp/_out2 &
jamfPID=$!
sleep 5
counter=0
while [[ $pkgPartial != $pkgTotal ]]
do
dialogStopCheck=`cat /tmp/_out`
if [[ "$dialogStopCheck" = "stopped" ]]
then
kill $jamfPID
rm -f /tmp/_out
rm -f /tmp/_out2
writeLog "Upgrade cancelled by user."
exit
fi
binaryUpgradeCheck=`cat /private/tmp/_out2 | grep "Upgrading jamf binary..."`
if [[ "$binaryUpgradeCheck" != "" ]]
then
kill $jamfPID
rm -f /tmp/_out
rm -f /tmp/_out2
writeLog "jamf binary upgrade detected. Fixing..."
jamf policy -event PayloadName >> "$logFile"
sleep 20
dialogDownload
fi
if [[ $counter -gt 9 ]]
then
echo "Package Download failed..." >&3
sleep 5
kill $jamfPID
writeLog "Package download failed."
exit
else
if [[ -f "$downloadFolder"/"$dmgName" ]]
then
pkgPartial=`du "$downloadFolder"/"$dmgName" | awk '{print $1}'`
modifiedTime=`stat -s "$downloadFolder"/"$dmgName" | awk '{print $10}' | sed 's/.*=//'`
currentTime=`date +%s`
timeDifference=`expr $currentTime - $modifiedTime`
if [[ $timeDifference -gt 10 ]]
then
echo "$xferPercentage Download may have stalled... ${xferPercentage}%" >&3
sleep 5
counter=$(expr $counter + 1)
else
if [[ $pkgPartial =~ ^-?[0-9]+$ ]]
then
xferPercentage=`echo "scale=0; $pkgPartial*100/$pkgTotal" | bc`
echo "$xferPercentage Downloading... ${xferPercentage}%" >&3
fi
fi
elif [[ -f "$waitingRoomFolder"/"$dmgName" ]]
then
writeLog "$dmgName downloaded to $waitingRoomFolder"
break
else
counter=$(expr $counter + 1)
fi
fi
done
echo "Closing progress bar."
exec 3>&-
rm -f /tmp/hpipe
}