DEPNotify Starter: Change Computer Name with Pop-up menu

bwoods
Valued Contributor

Posting to assist with the DEPNotify Starter and ADE workflows. This basically allows users to chose a location from a dropdown and correlate that choice to a short-name. For example, when "Asia-Remote" is selected, it becomes "ASREM" when it's time to set the computername.

Place this portion of the script in the POPUP section of the DEPNotify Starter.
Remember to set testing mode to "false" when you need to put this into production.

If you have an easier way to accomplish this, please post below. Some users on the macadmins channel say that this is possible using case statements.

# Popup 1
    #######################################################################################
        # Serial Number
            macSerial=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')

        # Label for the popup
            REG_POPUP_LABEL_1="Location"

        # Array of options for the user to select
            REG_POPUP_LABEL_1_OPTIONS=(
                "Asia-Remote"
                "Canada"
                "China"
                "Czechia"
                "Dublin"
                "Europe"
                "Germany"
                "HongKong"
                "India"
                "London"
                "Norway"
                "Poland"
                "Sweden"
                "Switzerland"
                "FinLand-Estonia-Latvia"
                "USA-Newjersey"
                "USA-PA"
                "USA-Texas"
                "USA-Remote"          
            )

        # Help Bubble for Input. If title left blank, this will not appear
            #REG_POPUP_LABEL_1_HELP_TITLE="Building Dropdown Field"
            #REG_POPUP_LABEL_1_HELP_TEXT="Please choose the appropriate building for where you normally work. This is important for inventory purposes."

        # Logic below was put in this section rather than in core code as folks may
        # want to change what the field does. This is a function that gets called
        # when needed later on. BE VERY CAREFUL IN CHANGING THE FUNCTION!
            REG_POPUP_LABEL_1_LOGIC (){
                REG_POPUP_LABEL_1_VALUE=$(defaults read "$DEP_NOTIFY_USER_INPUT_PLIST" "$REG_POPUP_LABEL_1")
                echo "Status: $REGISTRATION_BEGIN_WORD $REG_POPUP_LABEL_1 $REGISTRATION_MIDDLE_WORD $REG_POPUP_LABEL_1_VALUE" >> "$DEP_NOTIFY_LOG"
                if [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Asia-Remote" ]; then
                     Location="ASREM"
                     echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Canada" ]; then
                    Location="CAREM"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "China" ]; then
                    Location="ASCH"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Czechia" ]; then
                    Location="EUCZE"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Dublin" ]; then
                    Location="EUDUB"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Europe-Remote" ]; then
                    Location="EUREM"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Germany" ]; then
                    Location="EUGER"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Hong Kong" ]; then
                    Location="ASHK"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "India" ]; then
                    Location="ASIN"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "London" ]; then
                    Location="EUUK"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Norway" ]; then
                    Location="EUNOR"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Poland" ]; then
                    Location="EUPOL"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Sweden" ]; then
                    Location="EUSWE"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "Switzerland" ]; then
                    Location="EUSWI"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "FinLand-Estonia-Latvia" ]; then
                    Location="EUEST"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "USA-Newjersey" ]; then
                    Location="USNJ"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "USA-PA" ]; then
                    Location="USPA"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "USA-Texas" ]; then
                    Location="USTX"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                elif [ "$TESTING_MODE" = true ] && [ "$REG_POPUP_LABEL_1_VALUE" = "USA-Remote" ]; then
                    Location="USREM"
                    echo $Location
                    sudo "$JAMF_BINARY" setComputerName -name "$Location$macSerial"
                else
                    sleep 10 
                fi
            }
0 REPLIES 0