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 #Must know the size of the package
pkgPartial=0
downloadFolder="/Library/Application Support/JAMF/Downloads"
waitingRoomFolder="/Library/Application Support/JAMF/Waiting Room"
dmgName="Package.dmg"
## CocoaDialog Function
dialogDownload()
{
## Create the name pipe input for the progressbar & set brief pause
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
sleep 0.2
## Display progress bar with initial text settings
"$cdPath" progressbar --stoppable --title "Upgrade Package Download Progress" --text "Downloading..." --float < /tmp/hpipe > /tmp/_out &
exec 3< <(yes)
## Send progress through the named pipe
exec 3<> /tmp/hpipe
if { >&3; } 2> /dev/null
then
writeLog "Pipe RW verified"
else
writeLog "Pipe RW failed"
fi
#Determine PID of jamf process so it can be killed.
trap : SIGTERM SIGINT
echo $$
(jamf policy -event PayloadName ) > /tmp/_out2 &
jamfPID=$!
## Give the policy time to start
sleep 5
#Initialize error counter
counter=0
#While loop to generate package download percent
while [[ $pkgPartial != $pkgTotal ]]
do
#Watches for the output of CocoaDialog to equal stopped if "Stop" button is clicked. Cancels install.
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
#Watches for possible jamf binary being upgraded which will fail download of package.
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
#Error counter check. Die at 10 errors.
if [[ $counter -gt 9 ]]
then
echo "Package Download failed..." >&3
sleep 5
kill $jamfPID
writeLog "Package download failed."
exit
else
#If the package exists in the download folder determine percentage downloaded.
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 the downloading file has not been updated in the 10 seconds relative to the current time download may have stalled. Increment error counter.
if [[ $timeDifference -gt 10 ]]
then
echo "$xferPercentage Download may have stalled... ${xferPercentage}%" >&3
sleep 5
counter=$(expr $counter + 1)
else
#Calculate percentage
if [[ $pkgPartial =~ ^-?[0-9]+$ ]]
then
xferPercentage=`echo "scale=0; $pkgPartial*100/$pkgTotal" | bc`
echo "$xferPercentage Downloading... ${xferPercentage}%" >&3
fi
fi
#Determine if the file has been moved to the JAMF Waiting room. Exit loop if so to begin install.
elif [[ -f "$waitingRoomFolder"/"$dmgName" ]]
then
writeLog "$dmgName downloaded to $waitingRoomFolder"
break
else
counter=$(expr $counter + 1)
fi
fi
done
## Turn off progress bar by closing file descriptor 3 and removing the named pipe
echo "Closing progress bar."
exec 3>&-
rm -f /tmp/hpipe
}