How do I specify the MATLAB editor keybindings programmatically

I want to setup the keyboard keybindings as Windows Default Set and I would like to do this at startup using the startup.m because I want this setting to be set on a large number of systems.

The equivalent setting in the preferences dialog is: MATLAB > Keyboard > Shortcuts > Active Settings: Windows Default Set.

Proposal of startup.m after Suever's answer

See line 8

% TODO set startup script in $HOME/Documents/bin/matlab/startup.m in Terminal

% all commands here will be run at startup etc startup.m
% TODO set user path as relative by $HOME/Documents/bin/matlab/
%userpath('/home/masi/Documents/bin/matlab/')
% TODO How to set up userpath outside this Matlab script in Terminal?

% http://stackoverflow.com/a/38188945/54964
if ( not( com.mathworks.services.Prefs.getStringPref('CurrentKeyBindingSet') == 'Windows' ) )
        com.mathworks.services.Prefs.setStringPref('CurrentKeyBindingSet', 'WindowsDefaultSet.xml')
end

% Event errors else with touchpad scroll
!synclient HorizTwoFingerScroll=0

Matlab: 2016a
System: Linux Ubuntu 16.04

Upvotes: 0

Views: 334

Answers (1)

Suever
Suever

Reputation: 65430

If you want to do this programmatically you can do it using the undocumented functions for setting the preferences.

com.mathworks.services.Prefs.setStringPref('CurrentKeyBindingSet', 'Windows')

If you want a different keybinding, you can set the value explicitly from the preferences dialog and then call the following to retrieve the value.

com.mathworks.services.Prefs.getStringPref('CurrentKeyBindingSet')

This command should only have to be run once per MATLAB installation so placing it within the startup.m file may be overkill and would also prevent users from being able to change your default settings.

Upvotes: 3

Related Questions