Question

I'd like to write a shell script that uses xquartz.

Specifically the ‘Allow connections from network clients’ checkbox at Settings/Security has to be checked. Is there a way to do this programmatically ?

Was it helpful?

Solution

Xquartz settings are stored in ~/Library/Preferences/org.macosforge.xquartz.X11.plist, the key you are looking for is nolisten_tcp.

To allow connections from network clients use

defaults write org.macosforge.xquartz.X11.plist nolisten_tcp 0

To prevent connections use

defaults write org.macosforge.xquartz.X11.plist nolisten_tcp 1

For both cases Xquartz must not be running while you apply the change.

PS: To look at the content of the file you can use

plutil -p ~/Library/Preferences/org.macosforge.xquartz.X11.plist 

OTHER TIPS

Thanks @nohillside♦ and @dan for your answers.

In my case the command defaults write org.macosforge.xquartz.X11.plist nolisten_tcp 0 had had no effect. After some investigation I've figured out that the plist filename is a bit different in my system. So the command that ultimately worked for me is:

defaults write org.xquartz.X11.plist nolisten_tcp -bool false

Note that macosforge has been shutdown and projects moved to other places - so removing macosforge from the default name makes sense.

XQuartz settings or preferences are managed from the file ~/Library/Preferences/org.macosforge.xquartz.X11.plist and are managed by XQuartz to read and write them through the agent com.apple.cfprefsd.xpc.agent.

The undocumented clean way I found to manage this file is:

  1. Quit XQuartz

  2. Stop com.apple.cfprefsd.xpc.agent:

    launchctl stop com.apple.cfprefsd.xpc.agent
    
  3. Make a local copy of ~/Library/Preferences/org.macosforge.xquartz.X11.plist

    mkdir src ; cd src
    cp ~/Library/Preferences/org.macosforge.xquartz.X11.plist .
    plutil -convert xml1 org.macosforge.xquartz.X11.plist
    vi org.macosforge.xquartz.X11.plist
    

    just before the last line containing:

    </dict>
    

    insert:

            <key>nolisten_tcp</key>
            <false/>
    

    save and exit vi.

  4. Copy back this local copy on the original file:

    cp org.macosforge.xquartz.X11.plist ~/Library/Preferences
    
  5. Restart com.apple.cfprefsd.xpc.agent:

    launchctl start com.apple.cfprefsd.xpc.agent
    
  6. Restart XQuartz

Since I wanted to make editing of this preference file as easy as possible, I made a Makefile of the process. Here is this Makefile:

PREF=~/Library/Preferences/org.macosforge.xquartz.X11.plist
SRC=org.macosforge.xquartz.X11.plist
CFD=com.apple.cfprefsd.xpc.agent

pref:
        cp $(SRC) $(PREF)

install:
        nohup sh -c 'make kill ; make pref ; make start' &

kill:
        pkill startx
        launchctl stop $(CFD)

start:
        launchctl start $(CFD)
        sleep 5
        open /Applications/Utilities/XQuartz.app                                                                       
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top