Sublime Forum

Sublime Text Build 4192: Disabling Mouse Bindings wheel button3 noop Programmatically (bash) not working under Ubuntu 24.04 Wayland

#1

I am configuring Sublime Text as part of an nginx build script that will only be run one time. I have checked with stackoverflow and all related material is out of date and does not work with Wayland. I do not want to install addition GNOME utilities.

Here is the section of my build script that installs Sublime Text including my failed attempt to disable the mouse wheel button. Note that if i manually add the preferences->mouse bindings while in the Sublime Text Editor it works perfect. I just need to be able to do it programmatically. My main goal, if possible is to have this change made globally for all current and future users in Ubuntu 24.04 to avoid having to instruct each user how to do this every time I add a new user.

# Install Sublime Text
echo "Installing Sublime Text..."
curl -fsSL https://download.sublimetext.com/sublimehq-pub.gpg | sudo gpg --dearmor -o /usr/share/keyrings/sublime-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/sublime-archive-keyring.gpg] https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list > /dev/null
sudo apt update -y
sudo apt install sublime-text -y
# Set the default mime types to Sublime Text
xdg-mime default sublime_text.desktop text/plain
xdg-mime default sublime_text.desktop text/html
xdg-mime default sublime_text.desktop text/css
xdg-mime default sublime_text.desktop text/x-php
xdg-mime default sublime_text.desktop application/x-sh
xdg-mime default sublime_text.desktop text/x-python
xdg-mime default sublime_text.desktop application/javascript
# Get the list of users in the 'nginxadmins' group
echo "Copying mimeapps.list to all users in the nginxadmins group..."
# Loop through each user in nginxadmins group
for user in $(getent group nginxadmins | cut -d: -f4 | tr ',' ' '); do
    # Check if the user's home directory exists
    if [ -d "/home/$user" ]; then
        # Copy mimeapps.list from nginxadmin to the user's .config directory
        echo "Copying mimeapps.list to $user's home directory..."
        sudo cp /home/nginxadmin/.config/mimeapps.list /home/$user/.config/mimeapps.list
        # Ensure the correct ownership for the user
        sudo chown $user:$user /home/$user/.config/mimeapps.list
    fi
done
echo "Sublime Text has been installed successfully and mimeapps.list has been copied to all nginxadmins users!"
# Ensure the global User directory exists for all users
sudo mkdir -p /opt/sublime_text/Packages/User/
# Create the global sublime-mousemap file with the required configuration
echo '[
    {
        "button": "button3",
        "command": "noop"
    }
]' | sudo tee /opt/sublime_text/Packages/User/sublime-mousemap > /dev/null
    # Verifying the system-wide mousemap file is in place for all users
    ls -l /opt/sublime_text/Packages/User/sublime-mousemap
    echo "Sublime Text mouse wheel click has been configured successfully!"

I’m not sure if the path /opt/sublime_text/Packages/User/sublime-mousemap is correct?
Sublime Text Build 4192 is what gets installed and i want to keep with the newest version.

I hope I have given enough information, if not I would be happy to give you more. I know this code is a little over kill for this question but any code advice will be appreciated.
Thank you.

0 Likes

#2

Changing this for all current users would require that you specifically create a file named $HOME/.config/sublime-text/Packages/User/Default (Linux).sublime-mousemap for every user that currently exists on the system and populate it with a mousemap that blocks that binding, taking care that if such a user already has such a file that you don’t just remove their changes in favor of your own (so you’d need to make sure that you add it to an existing file).

For all future users, something like putting the correct structure under /etc/skel so that when a new user is created, that folder is automagically created with the binding already in it is likely the way to go.

Alternately, your script could modify /opt/sublime_text/Packages/Default.sublime-package by extracting out the Default (Linux).sublime-mousemap file, modifying it to alter that particular binding to be noop, and then updating the package file with the new version (the package file is just a zip with a different extension).

If you did that, it would affect everyone on the system regardless of whether their user exists or not.

If you go that route, I would also add a huuge comment banner in the part of the file you modify to specifically point out to anyone that looks at it that you’re the one that did it and why, so that the greater Sublime community doesn’t get confused if anyone asks why it’s that way. :slight_smile:

Side note on that, your change will get entirely blown away without a trace if you ever install a new version if you modify the Default.sublime-package file; so all else considered and for sanity reasons, the first method is probably better overall.

3 Likes

#3

Thank you for your reply.
I am not a linux nurd by any stretch.
I tried:
sudo cp ‘Default (Linux).sublime-mousemap’ /home/larry/.config/sublime-text/Packages/User/‘Default (Linux).sublime-mousemap’, but as you implied there might be multiple places were and files that are created when you use the actual app to create a new mapping.

Copying the file from one user to the other throws an error and corrupts sublime text. This makes me think that if I knew the paths to other files that are associated with the creation of a new /home/larry/.config/sublime-text/Packages/User/'Default (Linux).sublime-mousemap within the app then maybe I could copy those files or modify them for the different user. In other words there must be an entry put in some file somewhere that the app can log the fact that the home/larry/.config/sublime-text/Packages/User/'Default (Linux).sublime-mousemap was created by the app itself as opposed to an external copy.

I am not capable of reverse engineering the app.

If I don’t have to worry about future users and just run a script for existing users that would be better than nothing.

I wouldn’t want it to get blasted when an update is applied.

0 Likes

#4

Specifically, the directory that is created for user specific customizations to Sublime Text (on Linux) is /home/USERNAME/.config/sublime-text.

There are a few things that will be populated into that location, but for your purposes here Packages is the folder that you care about, and the User package is where user specific customizations go. If you were to start Sublime and use Preferences > Browse Packages, this is where you end up.

As far as what you’re talking about here, this is the only folder that you care about; it may not exist if a particular user has never run Sublime before, in which case you would need to create it first. You can do that with mkdir -p, which creates any folders needed and silently ignores if they already exist. So mkdir -p /home/bob/.config/sublime-text/Packages/User would make the folder for the user bob if it didn’t exist, but would happily do nothing if it did.

Not sure what you mean by “corrupts”, but note that Linux has a concept of file ownership and permissions.

For example:

tmartin:PCTERM:~/.config/sublime-text/Packages/User> ls -alF *.sublime-mousemap
-rw-r--r-- 1 tmartin tmartin 2255 Feb 22  2024 'Default (Linux).sublime-mousemap'

This particular file isowned by the user tmartin in the group tmartin, and the permissions are -rw-rw-rw- which goes in order of user, group, other. In this case the owner (me) can read and write, but my group and other people can only read the file.

Just copying a file from one user to another could keep the owner intact, and if the permissions are not correct, would stop Sublime from being able to read the file, or whoever you copied it to from being unable to modify it.

So, you probably want to make sure that the file and any folders you create are owned by the correct person. The command for that is chown.

Just the notion of who owns the file. Sublime itself only ever creates files inside of the /home/USERNAME/.config/sublime-text folder (and technically /home/USERNAME/.cache/sublime-text but that is of no concern to you here), so there’s no other location to put it.

0 Likes

#5

Thank you that solved half my problem and was a great help.
I managed to get it to work perfectly for all users. I simplified the script to work while logged in as a member of a group name nginxadmins with sudo privileges.
I run the script to configure user larry’s sublime text. The account for larry was just created and he has never logged into his account which also means he has never launched sublime text. Sublime text is installed on the machine already.

The script does basically two things:

  1. Creates a mousemap in larry’s account.
  2. Creates a spoofed sublime text session file which contains barebone settings

I had mentioned previously that if you manually create the mousemap file and run sublime text that it corrupts sublime text and you asked about it. Here is what I discovered, when you launch sublime text it looks for a session file located at /home/larry/.config/sublime-text/Local/Session.sublime_session, if it can’t find the file it will allow you to edit or create any file, but when you try to save it an error dialog box says it is unable to find the session file. If try to exit sublime text the error keeps displaying and it won’t let you exit “corrupted”.

Normally the file /home/larry/.config/sublime-text/Local/Session.sublime_session would exist but in this case larry has never logged into his ubuntu account after it was created therefore it doesn’t exist. In fact the /home/larry/.config/sublime-text is created the first time you run sublime text.

Here is the script that creates the basic directories, creates the mousemap and creates a minimal session file to kick start sublime text when he finally logs in and runs sublime text.

    #!/bin/bash
# Note: I am running this script from another user who is a member of nginxadmins group to gain permission to larry's home
# Create mousemap for each user
sudo mkdir -p "/home/larry/.config/sublime-text"
sudo chown larry:nginxadmins "/home/larry/.config/sublime-text"
sudo mkdir -p "/home/larry/.config/sublime-text/Packages/User/"
sudo chown larry:nginxadmins "/home/larry/.config/sublime-text/Packages"
sudo mkdir -p "/home/larry/.config/sublime-text/Packages/User/"
sudo chown larry:nginxadmins "/home/larry/.config/sublime-text/Packages/User/"
echo '[
    {
        "button": "button3",
        "command": "noop"
    }
]' | sudo tee /home/larry/.config/sublime-text/Packages/User/'Default (Linux).sublime-mousemap' > /dev/null
        sudo chown larry:nginxadmins /home/larry/.config/sublime-text/Packages/User/'Default (Linux).sublime-mousemap'
        echo "Sublime Text mouse wheel click has been configured successfully!"

# Create Session.sublime_session file to spoof sublime text session
sudo mkdir -p "/home/larry/.config/sublime-text/Local"
sudo chown larry:nginxadmins "/home/larry/.config/sublime-text/Local"
echo '{
"file_history":
[
],
"folder_history":
[
],
"last_version": 4192,
"last_window_id": 6,
"log_indexing": false,
"next_update_check": 1741894148,
"settings":
{
"new_window_full_screen": false,
"new_window_height": 600.0,
"new_window_maximized": false,
"new_window_position":
[
26.0,
96.0
],
"new_window_settings":
{
"auto_complete":
{
"selected_items":
[
]
},
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 0.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"file_history":
[
],
"find":
{
"height": 26.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"$user",
"udp_url"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
"larry"
],
"reverse": false,
"scrollbar_highlights": true,
"show_context": true,
"use_buffer2": true,
"use_gitignore": true,
"whole_word": false,
"wrap": true
},
"incremental_find":
{
"height": 26.0
},
"input":
{
"height": 0.0
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"pinned_build_system": "",
"replace":
{
"height": 48.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 150.0,
"status_bar_visible": true,
"template_settings":
{
}
},
"new_window_width": 1803.0
},
"windows":
[
{
"auto_complete":
{
"selected_items":
[
]
},
"buffers":
[
],
"build_system": "",
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 0.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"file_history":
[
],
"find":
{
"height": 26.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"$user",
"udp_url"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
"larry"
],
"reverse": false,
"scrollbar_highlights": true,
"show_context": true,
"use_buffer2": true,
"use_gitignore": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 26.0
},
"input":
{
"height": 0.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"pinned_build_system": "",
"position": "0,0,0,0,0,26,23,1829,623,1920,1080,0",
"project": "",
"replace":
{
"height": 48.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 150.0,
"status_bar_visible": true,
"template_settings":
{
},
"window_id": 1,
"workspace_name": ""
}
],
"workspaces":
{
"recent_workspaces":
[
]
}
}
' | sudo tee /home/larry/.config/sublime-text/Local/Session.sublime_session > /dev/null
        sudo chown larry:nginxadmins /home/larry/.config/sublime-text/Local/Session.sublime_session
        echo "Sublime Text Session Spoof has been configured successfully!"
0 Likes