How to pass User and Location values to script

myu
Contributor

I am trying to automate the creation of an Outlook signature and I have most of the parts down except I can't find a way to pass values from User and Location to the script. I thought passing $FULLNAME or $POSITION as script parameters would work but all it does is literally pass the string "$FULLNAME" to the script.

2 ACCEPTED SOLUTIONS

It seems as though your plist file is improperly formatted. Try reading another plist in the same directory (/Library/Managed Preferences) and you'll see what the difference is. None of the profile info should be there, ie PayloadContent etc

View solution in original post

myu
Contributor

OK, so I've deleted everything except just he key/value pairings and changed the keys to not have spaces. It's working now ...

 

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; <plist version="1"> <dict> <key>Computer_Jamf_Pro_ID_Number</key> <string>$JSSID</string> <key>Computer_Name</key> <string>$COMPUTERNAME</string> <key>Computer_MAC_Address</key> <string>$MACADDRESS</string> <key>Computer_Serial_Number</key> <string>$SERIALNUMBER</string> <key>Computer_UDID</key> <string>$UDID</string> <key>Computer_User_Email_Address</key> <string>$EMAIL</string> <key>Computer_User_Full_Name</key> <string>$REALNAME</string> <key>Computer_User_Office_Building_ID</key> <string>$BUILDINGID</string> <key>Computer_User_Office_Building_Name</key> <string>$BUILDINGNAME</string> <key>Computer_User_Department_Name</key> <string>$DEPARTMENTNAME</string> <key>Computer_User_Department ID</key> <string>$DEPARTMENTID</string> <key>Computer_User_Position</key> <string>$POSITION</string> <key>Computer_User_Room_Location</key> <string>$ROOM</string> <key>Computer_User_Phone_Number</key> <string>$PHONE</string> <key>Computer_User_Username</key> <string>$USERNAME</string> <key>Site</key> <string>$SITENAME</string> <key>Site_ID</key> <string>$SITEID</string> </dict> </plist>

 

Thanks Shannon! I was about ready to just awk and sed it  😀

View solution in original post

12 REPLIES 12

shannon_pasto
Contributor

You’ll probably need to do an API call to get that information. If you’re using Jamf Connect you could get some of the information from the com.jamf.connect.state.plist file for the user

myu
Contributor

I found this post on Der Flounder which suggested creating a config profile to store computer inventory information in a .plist file which could then be queried using a "defaults read" command. However, when I run the command, it tells me that the domain/pair cannot be found (I have created the sample config profile and I can see the /Library/Managed Preferences/com.company.information.plist file).

For that data to be in the profile it will need to be on the Jamf record at the time it installs on the Mac. 

Hi Shannon,

 

Yes, when I run "defaults read /Library/Managed Preferences/com.company.information.plist" I get a whole lot of data. But when I run "defaults read /Library/Managed Preferences/com.company.information.plist Company User's Name" I get the error "domain/default pair does not exist"

So you’ll need to install the profile after the data you require is populated on the jamf record or find another way to get the data

Maybe I am misunderstanding you but the data as far as I can tell is already populated ....

I can see them when I do a "defaults read /Library/Managed Preferences/com.company.information.plist" ... the output shows that the field "Computer User's Name" already contains the user's Full Name as recorded under User and Location.

 

And yet when I run "defaults read /Library/Managed Preferences/com.company.information.plist Computer User's Name"  I get an error

I believe the problem you’re seeing is with spaces. Plist keys should be written as a single word. Also, you need to put quotes around paths when those paths contain spaces.

Rename the key to a single word. Something like “ComputerUserName”.

The run:

defaults read "/Library/Managed Preferences/com.company.information.plist" ComputerUserName

Hi Moose,

 

I tried removing the spaces and then rebooting after removing the CP and re-applying it just to make sure but it made no difference.

 

Don't know how to attach images in a post so inserting a link to it instead ...

 

https://drive.google.com/file/d/1RJSGKBjtHpT4_i7RV0HNl-146vssMNDs/view?usp=sharing 

It seems as though your plist file is improperly formatted. Try reading another plist in the same directory (/Library/Managed Preferences) and you'll see what the difference is. None of the profile info should be there, ie PayloadContent etc

Yes, I was wondering about that as I didn't see those values in other PLISTs that I've uploaded before. Also, iMazing Profile Editor reported an "unfamiliar domain" error. I'm not deeply knowledgeable with PLISTs as I've only edited existing values before but never added different sections/areas. I'll give it a go and see what happens. Thanks.

myu
Contributor

OK, so I've deleted everything except just he key/value pairings and changed the keys to not have spaces. It's working now ...

 

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; <plist version="1"> <dict> <key>Computer_Jamf_Pro_ID_Number</key> <string>$JSSID</string> <key>Computer_Name</key> <string>$COMPUTERNAME</string> <key>Computer_MAC_Address</key> <string>$MACADDRESS</string> <key>Computer_Serial_Number</key> <string>$SERIALNUMBER</string> <key>Computer_UDID</key> <string>$UDID</string> <key>Computer_User_Email_Address</key> <string>$EMAIL</string> <key>Computer_User_Full_Name</key> <string>$REALNAME</string> <key>Computer_User_Office_Building_ID</key> <string>$BUILDINGID</string> <key>Computer_User_Office_Building_Name</key> <string>$BUILDINGNAME</string> <key>Computer_User_Department_Name</key> <string>$DEPARTMENTNAME</string> <key>Computer_User_Department ID</key> <string>$DEPARTMENTID</string> <key>Computer_User_Position</key> <string>$POSITION</string> <key>Computer_User_Room_Location</key> <string>$ROOM</string> <key>Computer_User_Phone_Number</key> <string>$PHONE</string> <key>Computer_User_Username</key> <string>$USERNAME</string> <key>Site</key> <string>$SITENAME</string> <key>Site_ID</key> <string>$SITEID</string> </dict> </plist>

 

Thanks Shannon! I was about ready to just awk and sed it  😀

shannon_pasto
Contributor

If all of the required data is there when you "defaults read /Library/Managed Preferences/com.company.information.plist" but not when you use the key then you have a syntax problem with the defaults command. Maybe it's the apostrophe?