hii @sirceljm
Good question this is one of those things that can be a bit confusing when you’re just starting with Collabora Online + UNO + postMessage.
- Can you select specific text programmatically?
Yes. Collabora Online exposes most of the LibreOffice UNO commands (the same you’d use in a desktop LibreOffice macro).
You can call them via postMessage into the editor frame. For example:
document.getElementById('iframe-id').contentWindow.postMessage({
"MessageId": "uno",
"args": {
"command": "SearchDialog", // or .uno:Search
"arguments": [
{ "name": "SearchItem.SearchString", "value": "MyText" },
{ "name": "SearchItem.Backward", "value": false },
{ "name": "SearchItem.Command", "value": 3 } // 3 = find all, 1 = find next
]
}
}, "*");
This won’t pop up the toolbar — it just runs the UNO command with the given parameters.
- About
DownSearch and others
Many of those names you see in the wiki (“DownSearch”, “UpSearch”, etc.) are old-style slot commands or macro helpers. In Collabora Online you normally stick to the .uno: commands (the desktop sends them on the wire too). For searching, the canonical command is .uno:ExecuteSearch.
Example:
postMessage({
"MessageId": "uno",
"args": {
"command": ".uno:ExecuteSearch",
"arguments": [
{ "name": "SearchItem.SearchString", "value": "hello" },
{ "name": "SearchItem.Backward", "value": false }
]
}
}, "*");
- Is there a “system” for arguments?
Yes — arguments are the same property names the desktop UNO dispatcher uses.
You can discover them in a few ways:
- Look at LibreOffice source code / wiki (search for
.uno:ExecuteSearch, .uno:GoToStartOfDoc, etc.).
- Open LibreOffice desktop with
--record-macro, perform an action, then inspect the recorded Basic macro. The argument names you see there are what you pass in JSON.
- In Collabora logs (
coolwsd.log) you can see which .uno: commands are triggered when you click UI buttons.
4. Can you use any UNO command?
Mostly yes, but:
- Collabora Online only implements a subset — most of the common editing/formatting/insert/search commands work.
- Things that require a modal dialog (like Tools ▸ Options) usually don’t exist in Online.
- For arguments, you must match exactly the expected property names and types (
string, bool, int).
So: Yes, you can select specific text programmatically. Use .uno:ExecuteSearch (or .uno:FindAll) with the right arguments, not the old DownSearch.
Thanks
Darshan