Recently, I was tasked with figuring out how to disable telemetry for Microsoft’s Visual Studio Code. Normally, you can disable telemetry in a Microsoft application through using a macOS configuration profile or by using a defaults command. In this case though, Microsoft bought Visual Studio Code along with the rest of Xamarin, and Xamarin had some different ideas on where and how to store settings.
In the case of Visual Studio Code, the command to disable telemetry is stored as a .json file in the following location:
/Users/username_here/Library/Application Support/Code/User/settings.json
After some research and some work with an open source tool named jq, I was able to figure out how to handle disabling the telemetry setting. For more details, please see below the jump.
The method I arrived at uses jq. This is a JSON manipulation tool which is not included with macOS, so I needed to install it separately before using it.
Once I had jq installed, I was able to write a script which did the following:
1. Checked to make sure the Mac in question was logged-in
2. Verified that the logged-in user was not the root user.
3. Verified that jq was installed at a location defined in the script and set as executable.
4. Checked for the existence of the settings.json file in /Users/username_here/Library/Application Support/Code/User.
If /Users/username_here/Library/Application Support/Code/User/settings.json is present, the script does the following:
A. Reads out the contents of the existing settings.json file.
B. Adds the following setting to the copied contents:
“telemetry.enableTelemetry”: false
C. Overwrites the existing settings.json file with the copied contents, which added the new telemetry setting.
D. Changes the ownership of the /Users/username_here/Library/Application Support/Code/User/settings.json file to that of the logged-in user.
If /Users/username_here/Library/Application Support/Code/User/settings.json is not present, the script does the following:
A. Creates the settings.json file in /Users/username_here/Library/Application Support/Code/User.
B. Adds the following setting to the newly-created file:
“telemetry.enableTelemetry”: false
C. Changes the ownership of the /Users/username_here/Library/Application Support/Code/User/settings.json file to that of the logged-in user.
5. Verifies that the telemetry.enableTelemetry setting is present and set to false.
The script is available below. It is also available from the following location on GitHub: