a week ago
Hey Everyone!
I have been at this for hours and I am not sure what I am doing wrong. I am trying to make an extention attribute that will display the users current keyboard input type. We have users in the UK and in the US and I have been asked to show if the users mac has a UK Keyboard or a US Keyboard.
This is my script, its very simple and I am not sure why its not showing a result in Jamf Pro. Even know it shows a result in terminal and code runner.
#!/bin/bash
# get the keyboard layout name
result=$(defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID)
echo "<result>$result</result>"
Here is my EA's Attributes
I am trying to find out if I need to contact jamf or am I missing something. Any help would be greatly appreciated!
Solved! Go to Solution.
a week ago - last edited a week ago
EA's run as root, so that defaults command is looking at root's keyboard settings, it needs to run as the currently logged in user, and of course if no one is logged in, it's still going to return nothing, so maybe store the result somewhere to use when no one is logged in.
#!/bin/bash
# get the keyboard layout name
username=$(who | grep console | awk '{print $1}')
userid=$(id -u $username)
result=$(launchctl asuser $userid sudo -u $username defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID 2>/dev/null)
if [ "$result" = "" ]; then
# Use root setting as backup
result=$(defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID 2>/dev/null)
else
# cache result in root
defaults write com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID -string "$result"
fi
echo "<result>$result</result>"
a week ago - last edited a week ago
EA's run as root, so that defaults command is looking at root's keyboard settings, it needs to run as the currently logged in user, and of course if no one is logged in, it's still going to return nothing, so maybe store the result somewhere to use when no one is logged in.
#!/bin/bash
# get the keyboard layout name
username=$(who | grep console | awk '{print $1}')
userid=$(id -u $username)
result=$(launchctl asuser $userid sudo -u $username defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID 2>/dev/null)
if [ "$result" = "" ]; then
# Use root setting as backup
result=$(defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID 2>/dev/null)
else
# cache result in root
defaults write com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID -string "$result"
fi
echo "<result>$result</result>"
a week ago
Dude your are a Life Saver Thank You SO Much! I knew I was overthinking something LOL