Skip to content

Use actual home directory for LaunchServices plist#24

Open
jimratliff wants to merge 2 commits into
macadmins:mainfrom
jimratliff:fix-relocated-home-directory
Open

Use actual home directory for LaunchServices plist#24
jimratliff wants to merge 2 commits into
macadmins:mainfrom
jimratliff:fix-relocated-home-directory

Conversation

@jimratliff

Copy link
Copy Markdown

Fixes handling for macOS accounts whose home directories are not under /Users/$USER.

default-browser currently constructs the LaunchServices plist path using /Users/<username>. That fails for accounts whose NFSHomeDirectory points to another volume, for example:

$ echo "$HOME"
/Volumes/some_personal_volume/Users/oliver

$ dscl . -read /Users/oliver NFSHomeDirectory
NFSHomeDirectory: /Volumes/some_personal_volume/Users/oliver

In that case, running default-browser --identifier ... fails while trying to create /Users/.

This change uses os.UserHomeDir() when constructing the default LaunchServices plist path, while preserving the existing WithPlistLocation override behavior.

This was referenced Jul 1, 2026
@grahamgilbert

Copy link
Copy Markdown
Member

I’ve refactored this section of the code so it can be tested. Could you please rebase on current main?

@jimratliff jimratliff force-pushed the fix-relocated-home-directory branch from 8cb0d31 to b7612cb Compare July 1, 2026 17:27

@grahamgilbert grahamgilbert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the home directory should become part of Client, following the existing option pattern, rather than being passed around separately. That keeps the client state coherent and makes the default plist path a derived value from the client.

For example:

type Client struct {
    Runner        osq.CmdRunner
    HomeDir       string
    PlistLocation string
}

func WithHomeDir(homeDir string) Option {
    return func(c *Client) {
        c.HomeDir = homeDir
    }
}

Then NewClient() can populate HomeDir from the current user by default, and PlistLocation can be derived from c.HomeDir unless WithPlistLocation(...) was provided.

I’d also prefer deriving the default home directory from user.Current().HomeDir rather than calling os.UserHomeDir() separately. user.Current() already gives us both the username and home directory, so keeping them from the same lookup avoids subtle mismatches.

Suggested behavior:

  • default NewClient() sets HomeDir from the current user and uses it for the LaunchServices plist path
  • WithHomeDir("/Volumes/foo/Users/bob") sets Client.HomeDir and uses that for the plist path
  • WithPlistLocation(...) still overrides everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants