How can I see which apple device is being used in our devices?

matias_picco
New Contributor

Hi everyone, we need to see which apple id is being used on every device we have enrolled in jamf. For this I've created an extension attribute that seems to work but only for a few hours. I don't understand why but after a while it goes from this:
8f24159e1fd1410897dbb08027f56352

to this:
119a8ece620749248a046238fec2551f

and if I run a sudo jamf recon it goes back to normal for another while but after sometime it keeps going bad.

this is the script that I'am using:

!/bin/bash

appleid=$(/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" ~/Library/Preferences/MobileMeAccounts.plist);

echo "<result>$appleid</result>"

exit 0

Do you have any suggestions or ideas about why this happening?

Thanks in advance

ps: I am pretty new to mac and jamf

1 ACCEPTED SOLUTION

sdagley
Honored Contributor II

@matias.picco EAs run as root, so you can't use ~ to refer to the current user's home directory. Try this (note that if no user is logged in this EA isn't going to return anything useful, so you should add some logic to accommodate that):

!/bin/bash

currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )

appleid=$(/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" /Users/$currentUser/Library/Preferences/MobileMeAccounts.plist);

echo "<result>$appleid</result>"

exit 0

View solution in original post

2 REPLIES 2

sdagley
Honored Contributor II

@matias.picco EAs run as root, so you can't use ~ to refer to the current user's home directory. Try this (note that if no user is logged in this EA isn't going to return anything useful, so you should add some logic to accommodate that):

!/bin/bash

currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )

appleid=$(/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" /Users/$currentUser/Library/Preferences/MobileMeAccounts.plist);

echo "<result>$appleid</result>"

exit 0

View solution in original post

matias_picco
New Contributor

Thanks sdagley! It seems to be working now. Since yesterday the info didn't go corrupt on the pc we are using for testing and it also started populating in other devices so it should be ok from now on. Thanks