Set asset tag policy fails with 10.9 and 9.22

spowell01
Contributor

as topic states, we have been using Tlarkin's script to prompt the user to set their asset tag, but that is no longer working with our casper suite 9.22 and Mavericks.

This is the script as we are currently using it:

#!/bin/bash

# use apple script and bash to get input from user to update asset tags in the JSS
# by Tom Larkin
# modified by Barnes, Walter 1/21/14
# proof of concept, no warranty given, use at own risk

# get user input from Apple Script and try to redirect output back into bash and user recon to update the JSS

VARIABLE=$(sudo /usr/bin/osascript <<-AppleScript

tell application "System Events" activate display dialog "Enter your asset number" default answer "Enter your Macbook's fixed asset tag number here" set theAnswer to (text returned of result) set cmd to "sudo /usr/sbin/jamf recon -assetTag " & theAnswer do shell script cmd
end tell

AppleScript)

$VARIABLE

exit 0

The JSS reports this error:Executing Policy Set Asset Tag...
[STEP 1 of 1]
Creating directory structure for /Library/Application Support/JAMF/Downloads/
Downloading https://kibsdjss.kibsd.org/Scripts/SetAssetTag.sh...
Running script SetAssetTag.sh...
Script exit code: 0
Script result: 38:46: execution error: An error of type -10810 has occurred. (-10810)

Any ideas as to what may be the culprit with the changes mentioned?

1 ACCEPTED SOLUTION

jhbush
Valued Contributor II

I had the same issue with the script. Cocoa Dialog ended up being a better option.

#!/bin/sh

# Set CocoaDialog Location

CD="/usr/local/bin/cocoaDialog.app/Contents/MacOS/CocoaDialog"

# Dialog to enter the computer name and the create $COMPUTERNAME variable
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the asset tag you wish to set"))

ASSETTAG=${rv[1]}


if [ "$rv" == "1" ]; then
    echo "User said OK"
elif [ "$rv" == "2" ]; then
    echo "Canceling"
    exit
fi 


# Set Hostname using variable created above
/usr/sbin/jamf recon -assetTag $ASSETTAG

# Dialog to confirm that the asset tag was set to.
tb=`$CD ok-msgbox --text "Asset Tag has been set to " --informative-text "The asset tag has been set to $ASSETTAG" --no-newline --float`

if [ "$tb" == "1" ]; then
    echo "User said OK"
elif [ "$tb" == "2" ]; then
    echo "Canceling"
    exit
fi

View solution in original post

7 REPLIES 7

tlarkin
Honored Contributor

Hey Sam,

Does the script run by itself in Mavericks just fine? Apple Script, for some things, requires a user session present. I have not tested this code against Mavericks yet either. Let me know if it works by running it manually. I suspect that may be part of the issue since Casper will run all scripts as root.

Thanks,
Tom

jhbush
Valued Contributor II

I had the same issue with the script. Cocoa Dialog ended up being a better option.

#!/bin/sh

# Set CocoaDialog Location

CD="/usr/local/bin/cocoaDialog.app/Contents/MacOS/CocoaDialog"

# Dialog to enter the computer name and the create $COMPUTERNAME variable
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the asset tag you wish to set"))

ASSETTAG=${rv[1]}


if [ "$rv" == "1" ]; then
    echo "User said OK"
elif [ "$rv" == "2" ]; then
    echo "Canceling"
    exit
fi 


# Set Hostname using variable created above
/usr/sbin/jamf recon -assetTag $ASSETTAG

# Dialog to confirm that the asset tag was set to.
tb=`$CD ok-msgbox --text "Asset Tag has been set to " --informative-text "The asset tag has been set to $ASSETTAG" --no-newline --float`

if [ "$tb" == "1" ]; then
    echo "User said OK"
elif [ "$tb" == "2" ]; then
    echo "Canceling"
    exit
fi

spowell01
Contributor

Thanks for the responses, Tom, your script did work fine when ran via terminal.

jhbush, thats an excellent alternative and looks like it will work well for us. I'm in the process of deploying cocoa dialog to all of our macs, but this should fit in perfect with our post image policies.

tlarkin
Honored Contributor

Hey Sam,

Yeah it is most likely because the root user is running the script and it has no user environment. Typically, I have deployed that script as a Self Service policy that level 1 techs can run after imaging. So, the work flow would be:

1 - Level 1 tech images the Mac
2 - Level 1 tech after imaging logs into the Mac and into Self Service with their LDAP credentials
3 - There is a post image provisioning script that runs, and it is only scoped to IT staff via their LDAP group
4 - Post image provisioning script runs, does things like ensures computer name, asset tag, BIND to AD, etc.
5 - Tech finishes the provisioning process and hands off to end user.

Cocoa Dialog is also pretty awesome and can do a lot of this pretty simply. You just have to deploy the app.

Hope this helps.

Thanks,
Tom

matthewbodaly
New Contributor

@jhbush1973][/url:

This is exactly what I was looking for. I have a few computers that I'm trying to get a little more information on. This was super helpful. I'm combining this with a script to rebind to AD and then reset all hostnames.

-
Followup.

Ended up combining this with a command to unbind from AD. I have another smart group to do the bind. This has worked well so far. I have a few more computers that need to check in.

jhbush
Valued Contributor II

@matthewbodaly][/url please post your script if you are permitted. Big thanks to @Andrina][/url for providing the template for the script.

matthewbodaly
New Contributor

Here is what I did

#!/bin/bash
# this ninja takes the name that the computer has in JAMF and then renames 
# all computer variables to that name AND adds a flat text file at
# /Library/Application Support/assettag
#
# Make a folder to store resource files. Commenting this out since this line isn't needed
# when the script is deployed via Casper. Uncomment to enable.
# mkdir /Library/Application Support/caspersupport
#
# force an unbind. 
dsconfigad -force -remove -u user -p babytownfrolics
#
#ask the user what their asset tag is
CD="/usr/local/bin/cocoaDialog.app/Contents/MacOS/CocoaDialog"
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "What is the barcode on this computer?"))
BELUS=${rv[1]}
if [ "$rv" == "1" ]; then
    echo "User said OK"
elif [ "$rv" == "2" ]; then
    echo "Canceling"
    exit
fi 
# Get for the name of the computer from Casper and write it to a file
# Use this if needed. Since we already asked the user the barcode... this doesn't have to be included.
# jamf -getComputerName | cut -c 16-24 > /Library/Application Support/caspersupport/assettag
# Set entry as a variable
echo $BELUS > /Library/Application Support/caspersupport/assettag
#
# Backup the file that will be changed
cp /etc/hostconfig /Library/Application Support/caspersupport/hostconfig.bak
# Change the HostName to the variable
scutil --set HostName $BELUS
# Change the ComputerName to the variable
scutil --set ComputerName $BELUS
# Write the variable to the end of /etc/hostconfig. This uses the FQDN. If you have a FQDN... you should change this.
echo HOSTNAME=$BELUS.apptio.lan >> /etc/hostconfig
# change the Bonjour name
systemsetup -setlocalsubnetname $BELUS
sudo jamf recon
#rebind to active directory

I ended up dumping it in GitHub too https://github.com/matthewbodaly/rawrscripts/edit/master/computernameninjaV2.sh

I need to clean up the comments a little bit. I also didn't include the part to rebind since that is in another policy.