Disable Keyboard Shortcuts using Python UNO API

Does anyone know how to disable the Keyboard shortcuts (for copy, save etc…) using Python UNO APIs. My need is to programmatically disable or enable these shortcuts without restarting the Libreoffice application.

How is this related to your other question at Disable Menu Item using Python UNO API? Perhaps you want to use that code along with Where does LO store keyboards/shortcuts?.

With regard to the other question relation, disabling the menu item doesn’t seem to automatically disable the keyboard shortcut associated with it. For example, the user can still copy the text using Cmd-C even if the copy menu item is disabled.

My need is to programmatically enable or disable the user from copy/exporting/saving the document.

For example, to disable saving by Ctrl+S:

xPropertyValue = PropertyValue()
xPropertyValue.Name = "nodepath"
xPropertyValue.Value = (
xAccess = self.uno_objs.configProvider.createInstanceWithArguments(
accelerator = xAccess.getByName('S_MOD1')
accelerator.setPropertyValue('Command', "disabled")

To enable again:

accelerator.setPropertyValue('Command', ".uno:Save")

View %appdata%\LibreOffice\4\user\registrymodifications.xcu to see the changes that are made. Changes take effect immediately when committed.

To show available properties and methods, print(dir(xAccess)) may be helpful.

I feel compelled to ask whether you really want to disable basic functions such as saving. It could be irritating for anyone who uses whatever you are making.

My assumption is that OP wants this as an attempt to create something like DRM preventing user from copying data. And that’s absolutely futile attempt, if I am right. Also interesting how well would it work when one switches between “protected” documents and unprotected ones, and how well would it behave on app crashes (when no cleanup code could bring settings back to normal state).

Thanks Jim, I will check and update.

@Mike2, you are right. Please let me know if there is a better solution to prevent the user from copying the document. Other than a case of user taking pictures of the screen, I am under the assumption that all other methods of copying can be controlled. I may be wrong, but I would like to try and achieve this goal.

@Jim key shortcut Cmd-S for Save seem to be disabled when “Save menu item” is disabled, I didn’t need to add the new code. But the copy (Cmd-C) is enabled even when the menu item is disabled. Is this a bug in LibreOffice? I also tried your new code but was still able to copy the data to clipboard.
Also, any idea on how remove the save prompt when you close application without saving the document? Appreciate your responses, thanks!

As far as the save prompt, you could set the file to open read-only as described at "Open file read-only" by default. Beyond that, I do not like the direction this is going. Perhaps you should be using pictures of the screen instead.

Even then, someone could take a picture to copy it. DRM files are evil. Those that I have purchased in the past no longer work, so I have been forced to circumvent the protection to get them to work.

I agree… Thanks for your replies. Appreciate it very much!