Skip to main content
Answer

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

  • October 5, 2020
  • 2 replies
  • 37 views

Forum|alt.badge.img+2

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:

to this:

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

Best answer by sdagley

@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

2 replies

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • Answer
  • October 5, 2020

@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

Forum|alt.badge.img+2
  • Author
  • New Contributor
  • October 6, 2020

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