Posted on 10-02-2014 12:47 PM
I was watching a Jamf webex and saw a policy to update asset tag via self service.
I really like the idea for support staff.
Has any one done something like thing?
Am going to guess its done via the API.
Solved! Go to Solution.
Posted on 10-02-2014 01:32 PM
#!/bin/sh
########################################################################
# Created By: Raul Santos, ras2060@med.cornell.edu
# Creation Date: Oct 2nd 2014
# Last modified: Oct 2nd 2014
#
# Brief Description: Interactive prompt to change the computer Tag, used in Self Service
#
# Modification History
# Oct 2nd - New Script
########################################################################
# Set CocoaDialog Location
CD="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Dialog to enter the computer name and the create $ASSETTAG variable
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the computer tag"))
ASSETTAG=${rv[1]}
# Set Hostname using variable created above
jamf recon -assetTag $ASSETTAG
# Dialog to confirm that the hostname was changed and what it was changed to.
tb=`$CD ok-msgbox --text "Computer Tag Added!"
--informative-text "The computer Tag has been added to $ASSETTAG"
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi
Posted on 10-02-2014 12:58 PM
Actually it can be done with a simple recon. Note the bolded item in the help page below:
$ jamf help recon
Usage: jamf recon
-saveFormTo Saves the contents of the HTTP form to a file
The following options allow you to specify inventory information for the computer:
**-assetTag The asset tag of the computer**
-endUsername The user name of the primary user
-realname The real name of the primary user
-email The email address of the primary user
-position The position (job title) of the primary user
-building The text representation of a building in the jSS
-department The text representation of a department in the JSS
-phone The phone number of the primary user
-room The room that the computer is in
-ldapServerID The JSS ID of the LDAP server to which the primary user belongs
-userID The user ID of the primary user's account in the LDAP server.
The following options allow you to update the computer's management account information in the JSS:
-sshUsername A username that is used to connect to the computer over SSH.
-sshPassword A password that is used to connect to the computer over SSH.
-sshPasshash A hashed copy of a password that is used to connect to the computer over SSH
Posted on 10-02-2014 01:32 PM
#!/bin/sh
########################################################################
# Created By: Raul Santos, ras2060@med.cornell.edu
# Creation Date: Oct 2nd 2014
# Last modified: Oct 2nd 2014
#
# Brief Description: Interactive prompt to change the computer Tag, used in Self Service
#
# Modification History
# Oct 2nd - New Script
########################################################################
# Set CocoaDialog Location
CD="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Dialog to enter the computer name and the create $ASSETTAG variable
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the computer tag"))
ASSETTAG=${rv[1]}
# Set Hostname using variable created above
jamf recon -assetTag $ASSETTAG
# Dialog to confirm that the hostname was changed and what it was changed to.
tb=`$CD ok-msgbox --text "Computer Tag Added!"
--informative-text "The computer Tag has been added to $ASSETTAG"
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi
Posted on 10-02-2014 01:39 PM
Nice!
The only thing is, why do the 'ok-msg' style at the end? Isn't that just an informative window telling the user that the asset tag was successfully assigned? Having a 'Cancel' button in the dialog could be confusing, since it isn't actually canceling anything, no?
Posted on 10-02-2014 01:41 PM
agreed that can be removed will post an updated version.
Posted on 10-02-2014 01:58 PM
Something else I recommend doing, if you don't mind the suggestion.
Consider adding this flag to the end of your first cd inputbox dialog that asks for the Asset Tag
--value-required
This will force the user/tech to enter a tag value before they can click "Okay", or they can click "Cancel" to exit.
As a bonus, you can customize the text that appears in the sheet that is displayed if they click OK before entering anything with the following
--empty-text "your custom text here"
These by the way are only available in the 3.0 beta releases, not in the last official 2.1.1 release, but it looks like that's what you're using.
Posted on 10-02-2014 05:07 PM
Or not relying on CocoaDiaolog...
#!/bin/sh
osascript -e 'tell application "System Events" to set visible of process "Self Service" to false'
asset=$(/usr/bin/osascript <<-'__EOF__'
tell application "System Events"
activate
set input to display dialog "Enter Asset Number: " default answer "" buttons {"OK"} default button 1
return text returned of input as string
end tell
__EOF__
)
jamf recon -assetTag $asset
exit
Edit: Ugh, sorry guys. I hadn't purged the last of our unique variables. Everything uses $asset now. @emilykausalik - the script will work for you now. As always test, test, test...
Posted on 10-03-2014 06:43 AM
@tsuter nice job now I like the idea I think many of us on here are a big fan of cocoaDialog a bit too much.
Posted on 10-03-2014 07:46 AM
This would be incredibly useful for my team as a Self Service tool, but neither of the provided scripts are working for some reason. Has anyone else been using these scripts and having them kick off correctly?
Posted on 10-03-2014 08:08 AM
I used the cocaDialog-based version and it worked correctly in my testing.
Posted on 10-03-2014 08:15 AM
Hm. My cocoaDialog is in /Library/Applications Support/JAMF/bin. No matter how I try to call that directory it says it doesn't exist. My shell-fu is not strong today apparently.
Posted on 10-03-2014 08:24 AM
It would be "/Library/Application Support/JAMF/bin"
not "/Library/Applications Support/JAMF/bin"
Note the extra "s" Not sure if you just typed that in manually or if was copy.pasted from your script, but if the latter, that would be why its saying it doesn't exist.
Posted on 10-03-2014 08:31 AM
Ah yeah, no, that was a typo here. Here is my version of the script:
#!/bin/sh
########################################################################
# Created By: Raul Santos, ras2060@med.cornell.edu
# Creation Date: Oct 2nd 2014
# Last modified: Oct 2nd 2014
#
# Brief Description: Interactive prompt to change the computer Tag, used in Self Service
#
# Modification History
# Oct 2nd - New Script
########################################################################
# Set CocoaDialog Location
CD="/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Dialog to enter the computer name and the create $ASSETTAG variable
rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the computer tag"))
ASSETTAG=${rv[1]}
# Set Hostname using variable created above
jamf recon -assetTag $ASSETTAG
# Dialog to confirm that the hostname was changed and what it was changed to.
tb=`$CD ok-msgbox --text "Computer Tag Added!"
--informative-text "The computer Tag has been added to $ASSETTAG"
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi
I keep getting:
AssetTag.sh: line 18: /Library/Application: No such file or directory
Maybe I just need more coffee but I've tried every way I could possibly call that directory and none of them work. Shell hates me today apparently.
Posted on 10-03-2014 08:34 AM
@emilykausalik,
Quote your CD variable in the script when you use it, like:
rv=($("$CD" standard-inputbox....
The problem is that since 'Application Support' has a space in it, not quoting it when you used the variable for CD was expanding and not escaping the space in the path.
Should work after you do that.
Posted on 10-03-2014 08:39 AM
Yeah! I actually figured that out right before you posted here. With a little help from one of our Linux gurus.
I love this forum.
Posted on 09-23-2015 05:20 PM
@emilykausalik i wanted to reach out to see if you every got a finalized script for the asset tags to be captured in the JSS v9.8. I currently have one running on enrollment and also living in self service for existing machines but it generates an error in the log files Script result: 36:82: execution error: System Events got an error: Can’t set process "Self Service" to false. (-10006)
Can anyone help with a working script?
Posted on 09-23-2015 06:22 PM
Here's what I've been using:
#!/bin/sh
#
# prompts user for company asset tag for inventory
# adapted by emilyk
# 2014-10-03
#
# Set CocoaDialog Location
CD="/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Dialog to enter the computer name and the create $ASSETTAG variable
rv=($("$CD" standard-inputbox --title "Company Asset Tag" --no-newline --informative-text "Enter the Company Asset Tag" --value-required))
ASSETTAG=${rv[1]}
# Set Hostname using variable created above
jamf recon -assetTag $ASSETTAG
# Dialog to confirm that the hostname was changed and what it was changed to.
tb=`"$CD" ok-msgbox --text "Company Asset Tag Added!"
--informative-text "The computer's Company asset tag has been added to $ASSETTAG."
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi
I can't speak to 9.8 as I haven't tried it on that version of the JSS yet. Give it a shot and let me know. Might need to adjust the location of CD and whatever text you want in the popup dialog.
Posted on 02-12-2020 03:00 PM
I've modified the dialog box and set it to only ask for Asset Tag.
#!/bin/sh
#!/bin/bash
########################################################################
# Created By: Raul Santos, ras2060@med.cornell.edu
# Creation Date: Oct 2nd 2014
# Last modified: Feb 11 2202 lrahn@chime.com
#
# Brief Description: Interactive prompt to change the computer Tag, used in Self Service
#
# Modification History
# Oct 2nd - New Script
########################################################################
# Feb 11 2020 - Updated Dialog box to built in dialog
# Only updating Asset Tag
# Set CocoaDialog Location
# CD="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/cocoaDialog"
# Dialog to enter the computer name and the create $ASSETTAG variable
#rv=($($CD standard-inputbox --title "Asset Tag" --no-newline --informative-text "Enter the computer asset tag"))
#ASSETTAG=${rv[1]}
TAG=`/usr/bin/osascript <<'EOT'
tell application "System Events"
activate
set TAG to text returned of (display dialog "Please Input The Asset Tag - " default answer "" with icon 2)
end tell
EOT`
echo $TAG
# Set Hostname using variable created above
sudo jamf recon -assetTag $TAG
exit 0