HexCon is coming to NYC. Catch the early-bird price before the time's up! Book me a spot

Custom script not fetching currently logged in userSolved

Participant
Discussion
2 years ago

Found a script to check if a user is signed in to the Box client app on Mac. The script is successful when run locally on the device, but there’s an issue when run remotely from hexnode. I’m guessing the user variable in the script isn’t fetching the currently logged in user like it would when run locally from the mac.

This is the script:

#!/bin/sh

if [ -f /Users/$loggedInUser/Library/Preferences/com.box.desktop.plist ]; then

loggedin=$(defaults read /Users/$loggedInUser/Library/Preferences/com.box.desktop preferences/user_is_currently_logged_in)
echo “<result>$loggedin</result>”
else
echo “<result>File Not Found</result>”
fi

You guys got any ideas?

Replies (2)

Marked SolutionPending Review
Participant
2 years ago
Marked SolutionPending Review

Fetching the ‘LastUserName’ key from the com.apple.loginwindow plist file would supposedly work. Check out this script:

#!/bin/sh

loggedInUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)

if [ -f /Users/$loggedInUser/Library/Preferences/com.box.desktop.plist ]; then
loggedin=$(defaults read /Users/$loggedInUser/Library/Preferences/com.box.desktop preferences/user_is_currently_logged_in)
echo “<result>$loggedin</result>”
else
echo “<result>File Not Found</result>”
fi

 

Marked SolutionPending Review
Participant
2 years ago
Marked SolutionPending Review

Brilliant! That worked.