When it comes to scripting I'd say I'm mediocre compared to most folks so I need some help really nailing down a DO loop which I don't really use very often.
Purpose of the script: We use ARD to remote into machines so we populate ARD Field #1 on our machines to with the asset tag number that applies to the machine; found on a sticker on the bottom of the laptop. We're looking at moving over to DEP and I'll need a way for the user to enter the asset tag number for us since we, as techs, are no longer doing since we're not building the machine any longer.
I'd like for the script to basically not exit until the user has entered an integer into Cocoa Dialog field that is appearing on screen. It's mostly working but it's definitely not pretty and the pop-ups are not appearing in the order I'd like every single time.
#!/bin/bash
## Global Variables
CD="/Applications/Utilities/CocoaDialog.app/Contents/MacOS/CocoaDialog"
jamfHelper='/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper'
icon='/Users/Shared/icon.png'
## Global functions
enterTag()
{
tag=`"${CD}" standard-inputbox --title "Asset Tag Number Required" --informative-text "Please enter the asset tag number of your computer" --text "Your asset tag can be found on the bottom of your laptop." --float --no-cancel | tail -1`
if [[ $tag =~ ^-?[0-9]+$ ]]; then
intCheck="0"
else
"${jamfHelper}" -windowType utility -icon "$icon" -title "Incorrect Asset Tag Entered" -description "Letters are not allowed in your asset tag. Please re-enter your asset tag using only numbers" -button1 "OK" -defaultButton 1
intCheck="2"
fi
}
## Run the function
enterTag
echo "pre-loop"
while [[ $intCheck == "2" ]]; do
enterTag
echo "first do loop"
done
tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag.
Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`
while [ $tagConfirm == "2" ]; do
echo "second do loop"
enterTag
tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag.
Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`
while [ "$intCheck" = "2" ]; do
echo "third do loop"
enterTag
tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag.
Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`
done
done
#/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set1 -1 $tag
Any help would be greatly appreciated!
Thanks!
Chris
