Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Finds user's home directory with dscl (Issue #73) #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@


loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
homeDir=$(/usr/bin/dscl . read /Users/${loggedInUser} NFSHomeDirectory | /usr/bin/awk '{print $2}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the NFSHomeDirectory is set to /Volumes/Users HD/Users/ygi the awk command will only return /Volumes/Users.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. I'll do some testing and resubmit.

Copy link

@elyscape elyscape Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@canalnoises You could do this:

homedir="$(/usr/bin/dscl -plist . read "/Users/${loggedInUser}" NFSHomeDirectory | /usr/bin/xpath -q -e '//key[text()="dsAttrTypeStandard:NFSHomeDirectory"][1]/following-sibling::array[1]/string[1]/text()')"

Explanation of the parts follows.

/usr/bin/dscl -plist . read "/Users/${loggedInUser}" NFSHomeDirectory

This will output a plist that looks like this:

<?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">
<plist version="1.0">
<dict>
	<key>dsAttrTypeStandard:NFSHomeDirectory</key>
	<array>
		<string>/Volumes/Users HD/Users/ygi</string>
	</array>
</dict>
</plist>

We want to get the first/only value of dsAttrTypeStandard:NFSHomeDirectory, so we pass it into xpath with the following query:

//key[text()="dsAttrTypeStandard:NFSHomeDirectory"][1]/following-sibling::array[1]/string[1]/text()

Breaking the query down:

//key[text()="dsAttrTypeStandard:NFSHomeDirectory"][1]

This selects the first <key> element whose content is dsAttrTypeStandard:NFSHomeDirectory.

/following-sibling::array[1]

This selects the first <array> element that follows the selected <key> element.

/string[1]/text()

This returns the content of the first <string> element that descends from the selected <array> element.

Copy link

@elyscape elyscape Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could do this:

homeDir="$(/usr/bin/dscl . read "/Users/${loggedInUser}" NFSHomeDirectory | /usr/bin/sed 's/^NFSHomeDirectory: //')"

Whichever you do, you should put quotes around both the $() and the userpath, in case either the result or the userpath contains spaces.



app="/Library/Application Support/SplashBuddy/SplashBuddy.app"
doneFile="/Users/${loggedInUser}/Library/Containers/io.fti.SplashBuddy/Data/Library/.SplashBuddyDone"
doneFile="${homeDir}/Library/Containers/io.fti.SplashBuddy/Data/Library/.SplashBuddyDone"

# Check if:
# - SplashBuddy is not already running
Expand Down