FAQ: how to work with UNO commands

Hi, there were questions about using UNO commands in our code. I answered on our Telegram channel but I decided to create this post to make it archived:

  1. What is UNO command?
    UNO commands are commands to trigger some actions/dialogs inside LibreOffice, our “core”. Example command: .uno:SetOptimalRowHeight

  2. How to send UNO command to the server?
    You can call it on a “map” object which is accessible from many places: map.sendUnoCommand('.uno:SetOptimalRowHeight');

  3. How to get UNO command result?
    Here is an example of catching a command state updates:
    online/Control.Toolbar.js at 585974e3715c56897093d8c1ecd0d1c2f65b4631 · CollaboraOnline/online · GitHub
    map.on('commandresult', onCommandResult); registers a callback which will receive notification about all command results.
    If you want to query command state only one time, there is a helper already:
    map['stateChangeHandler'].getItemValue('.uno:DeletePage');

  4. Where is any UNO commands documentation?
    You need to look into LibreOffice codebase and documentation. Example:
    https://wiki.documentfoundation.org/Development/DispatchCommands
    This is a list of UNO commands with short description, under “SDI” link you can find declaration with required parameters and result type.

2 Likes
  1. My command doesn’t get status updates in Collabora Online.
    You need to enable it in the “core” LibreOffice, example: https://gerrit.libreoffice.org/c/core/+/132585

  2. My command needs more params, how to sent them?
    See more advanced example: online/Control.RowHeader.js at 46e6f6b4ba1b4b06661a76e259856d7ae9b9e4c0 · CollaboraOnline/online · GitHub

var command = {
	RowHeight: {
		type: 'unsigned short',
		value: this._map._docLayer.twipsToHMM(Math.max(height, 0))
	},
	Row: {
		type: 'long',
		value: row + 1 // core expects 1-based index.
	}
};
map.sendUnoCommand('.uno:RowHeight', command);```