Altsearch assign macro to key fails

I have been using the very useful AltSearch extension with key shortcuts in OO (on macOS) for many years. Recently I changed to LO (v.24.2.6.2 on macOS 13.6.9) but found that key shortcuts do not work. Earlier versions of LO on mac had the same problem.

To assign a shortcut key to a Batch in AltSearch you use the GUI shown.
Screenshot 2024-09-27 at 7.34.39 pm

But I get this Libre message when trying to assign a shortcut key to any batch including my own or in-built AltSearch batches.

A Scripting Framework error occurred while running the Basic script vnd.sun.star.script:Standard.AltSearchBatchs.0?language=Basic&location=application.
Message: The following Basic script could not be found:
library: ‘Standard’
module: ‘AltSearchBatchs’
method: ‘0’
location: ‘application’

Note:
All batches run successfully from AltSearch or from LO ‘Organize Batches’.

I can assign keys to custom macros recorded directly in LO (not via AltSearch) which are saved to ‘Standard/Module 1’ etc.

From my investigations it seems that:

All built-in and user-built AltSearch Batch scripts are saved on macOS in the single .txt file:
/Users/myname/Library/Application Support/LibreOffice/4/user/config/AltSearchScript.txt

When you assign a key to an AltSearch batch no extra macro is added to the list at LO/My Macros & Dialogs/Standard/AltSearchBatchs but an extra subroutine is added to each of the 3 existing macros that reads (for example):

Sub 0
On Error resume next
GlobalScope.BasicLibraries.LoadLibrary(“AltSearch”)
_AltSearch(“Para to line-break”)
End sub

  • and that has the Error Message ‘BASIC syntax error. Symbol expected’ on the first line ‘sub 0’ of the subroutine.

My Attempts to Fix:

There is no such ‘AltSearchBatchs.0’ so I tried adding xba (can’t do) or nothing (crashes) in the ‘Assign to key_Auxiliary Subroutine’ window instead of 0 (zero).
Note: from reading Andrew Pitonak’s excellent ‘OpenOffice.org Macros Explained’ (a bit beyond my scope) .0 (zero) is an illegal start to a sub Name.

So then I tried adding a custom name to the subroutine (e.g. ‘Para_to_Linebreak’) either via the AltSearch fill-in or by editing the ‘AltSearchBatchs’ macro. This does fix the BASIC error message and does add a new macro to the Standard/AltSearchBatchs index. But when I apply a key shortcut to that batch using LO ‘Macros_Organise’ that key shortcut doesn’t work either - there is no response (no error message, no run of the macro).
And, yes, I restart LO after each such change.

Any help would be hugely appreciated.

Adding to my original question. It seems that trying to assign a key to any AltSearch macro or batch causes problems. For instance, the simple assigning of Cmd_H to ‘open AltSearch dialog’ (Tools/Macros/Organize Macros/Basic/My Macros/Standard/AltSearchBatchs/AltSearch___dialog) does not open the AltSearch input pane but causes the LO document window to close.

Is anyone able to successfully assign a key to AltSearch macros or batches on LO macOS? If so, how? Does it work on Windows or Linux?

Regarding Windows, Windows 11 to be precise, the following summarizes my experience (“trials and tribulations”, if you like).

Tests with versions: 24.2.6.2 and 24.8.2.1 [1] (always fresh install).

  1. simple “Replacing one letter with another” saved as a batch.
    Result: new entry in the file AltSearchScript.txt

  2. Key shortcut assigned (I used the combination Ctrl+Alt+Shift+Right too).
    Two variants for Basic subroutine name: “0” (suggested by AltSearch) and my own string.
    Result: the extension for both variants made:

  • a new entry in ToolsCustomizeKeyboard tab for Ctrl+Alt+Shift+Right
    “vnd.sun.star.script:Standard.AltSearchBatchs.0?language=Basic&location=application”
  • a new subroutine in Basic located in Standard.AltSearchBatchs. It has a faulty name “0”.
    Shortcut does not work (missing Basic script).
  1. Remedy:
  • change the name of subroutine to something acceptable
  • in Tools CustomizeKeyboard tab assign Ctrl+Alt+Shift+Right
    to the renamed subroutine.

Result: the key shorcuts Ctrl+Alt+Shift+Right seems to work correctly.


----- Ref.:
[1]
Version: 24.2.6.2 (X86_64) / LibreOffice Community
Build ID: ef66aa7e36a1bb8e65bfbc63aba53045a14d0871
CPU threads: 8; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-US (pl_PL); UI: en-US
Calc: threaded

Version: 24.8.2.1 (X86_64) / LibreOffice Community
Build ID: 0f794b6e29741098670a3b95d60478a65d05ef13
CPU threads: 8; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Raster; VCL: win
Locale: en-US (pl_PL); UI: en-US
Calc: threaded

Thank you greatly cwolan for your effort and “trials and tribulations”.
I have tried many variations on your suggested remedy but it does not work on macOS.
The main difference is at:

MacOS does not add any new entry (0 or a legal string)

The only solution I have found to get an AltSearch batch assigned to a key on macOS is the following:

  • cwolan or another, you may wish to edit and re-format the following and add alternative steps for Windows or Linux users and submit it as a possible solution. I’m a newbie!

Have a Writer or Calc document open.

  • I suggest using a temporary test document first off as you will want to test your results without trashing a valuable document. Put in some random text that you want to experiment with.
  1. Enter your Batch using Alternative Find & Replace (AltSearch).
  • You can test your Batch using Replace or Replace all.
  • If you do test then you will need to reopen the AltSearch pane

With your batch showing in the pane:
2. Batch>>-Save Batch-and choose an appropriate short name

  • e.g. Change_a_2_b
  • do not begin that name with a number.
  • Keep a note of the exact name you entered. You will need it later.
    Result
  • On mac: this will save a new sub-routine with the name you entered to the file /Users*/username*/Library/Application Support/LibreOffice/4/user/config/AltSearchScript.txt
  • this where all AltSearch batches are stored.

On macOS: do not try to assign a shortcut key to your batch using AltSearch.

  1. Close the Alt Search pane.

  2. Go to Tools-Macros-Organize Macros-Basic-My Macros-Standard and select AltSearchBatches.

  • You should see a list of at least 3 Existing Macros. (Dialog, Find next, Find previous) .
  1. Select ‘Edit’
  • Note: on MacOS you cannot edit this file via AltSearch as AltSearch refuses to recognise TextEdit as a text editor.
  1. Copy the BASIC script for Standard-AltSearchBatchs to a new temporary text file as a backup in case you corrupt this vital file.

  2. Copy & Paste one of the sub-routines (preferably one that is already working with a key shortcut) to the end of the file.

  • You can separate the paste with a couple of empty paragraphs.
  1. Edit the pasted sub-routine to read exactly:
    Sub a new short descriptive name
    On Error resume next
    GlobalScope.BasicLibraries.LoadLibrary(“AltSearch”)
    _AltSearch(“the exact name you entered for your batch”)
    End sub
  • The subroutine should look like this (for example):
    Sub Altsearch___Change_A_to_B
    On Error resume next
    GlobalScope.BasicLibraries.LoadLibrary(“AltSearch”)
    _AltSearch(“Change_a_2_b”)
    End sub
  1. File-Save and close the pane.

  2. Go to: Tools-Macros-Organize-Basic-Standard-AltSearch

  • You should see a new item (e.g. ‘AltSearch__Change_A_to_B’) in the list of existing macros.
  1. Select that item.
    Assign that item to whatever key combination you wish.
  • -If that combination is already in use then you will need to delete that use first.
  • Note: trying to assign a key via Tools-Customize-Keyboard does not work on MacOS as no custom or installed AltSearch batches appear in the list of existing macros. This means that you cannot choose to assign the macro to the current document only (where it transferred with the document) or globally in Writer and Calc (it will not be transferred with the document). A smarter person than I may be able to suggest an edit to the Standard-AltSearchBatchs file to change this.
  1. Test the shortcut key combination.
  • It should work as expected.

Don’t mention it. Your “trials and tribulations” are no doubt tougher than mine.

My further tests on Windows:
The shortcut key assignment via AltSearch fails somewhere after 6.1.0.1. It certainly doesn’t work in 6.3.0.1. In the extension code (library AltSearch, module KeyAssign) I Iooked at the LatinFilter subroutine:

' filtrace znaků pro nazeb basic makra
sub LatinFilter(vst as string) as string
dim i, ch
dim vyst
  
 for i = 1 to len(vst)
  ch = mid(vst,i,1)
  
  [...]

    vyst = vyst + ch
  next i

 LatinFilter = vyst

end sub

Out of curiosity, on the line vyst = vyst + ch I duly replaced “+” with “&”, zipped the extension back and installed it. Now the shorcut assignment in AltSearch seems to function in e.g.: 6.3.0.1, 7.6.7.2, 24.2.6.2 and 24.8.2.1 (also in the “unaffected” 6.1.0.1).

1 Like

I had never used this AltSearch function, I think I tried it at some point but it didn’t work for me.
With that small modification it works perfectly. (in Windows)
Thank you very much @cwolan for the advice.

You can directly edit the module in the L.O. IDE. Basic (no need to unzip, rezip and reinstall)

  • Unless you want to have the extension corrected for future installations
1 Like

Thank you cwolan & bantionof. Brilliant! It works on macOS as well.

For dummies like me the simpler fix is the Bantionof method:
After installing Alternative Find & Replace extension:

  1. In a LO Writer document Go to: Tools-Macro-Edit Macros then choose My Macros-AltSearch-Key Assign-Latin Filter.
  2. Double-click Latin Filter to open it.
  3. Scroll down to (approximately) Line 492 vyst = vyst + ch
  4. Change that line to vyst = vyst & ch
  5. Compile the BASIC file (button on toolbar)
  6. File Save and close the editing window.

You should now be able to assign key shortcuts to your AltSearch macros within AltSearch.
You can also edit and change key allocations using LO Tools. See the discussion above.

If you wish to use the cwolan original method:
On macOS I found the file at: /Users/username/Library/Application Support/LibreOffice/4/user/uno_packages/cache/uno_packages/lu10921rk1.tmp_/AltSearch.oxt/AltSearch/KeyAssign.xba

It would be great if someone could apply this fix to the ‘Alternative searching 1.4.2’ package available for download through LO_Extensions.

1 Like