[Solved] Macro to paste a specific character

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
djwebb1969
Posts: 7
Joined: Mon Mar 13, 2023 6:16 pm

[Solved] Macro to paste a specific character

Post by djwebb1969 »

I find the right and left hand curly quotes hard to find in Office Symbol. I want toolbar buttons to paste them. I've done the following, which doesn't work. I thought that if I put in ".uno:Paste", "", 0, Array()) it would work. What is the correct syntax?

Code: Select all

sub curlysingleleft
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "‘", 0, Array())


end sub
Last edited by djwebb1969 on Wed Mar 12, 2025 7:49 pm, edited 4 times in total.
Open Office 4.1.14, Ubuntu 20
User avatar
MrProgrammer
Moderator
Posts: 5264
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Macro to paste a specific character

Post by MrProgrammer »

djwebb1969 wrote: Wed Mar 12, 2025 6:36 pm What is the correct syntax?
You have an example of a macro which uses dispatcher services. This type of macro comes from using the Tools → Macros → Record feature. The syntax and semantics of dispatcher macros are not documented. You have two choices.

The simplest method is to record four macros which use Insert → Special Character. Recording simple macros to perform one action will take less than a minute. The characters you want are probably:
• U+2018 Left Single Quotation Mark
• U+2019 Right Single Quotation Mark
• U+201C Left Double Quotation Mark
• U+201D Right Double Quotation Mark
When you record macros, you don't need to learn about macro syntax because OpenOffice creates the macro for you. Do not attempt to understand or modify recorded macros. Just use what you're recorded.

You could also write your macros and not use the macro recording feature. The syntax for that is documented but learning how to write macros is difficult. Expect to spend at least a week to write your first macro, more if you're not already a programmer.
OpenOffice.org Macros Explained

Instead of using a macro, I recommend using the AutoText feature of Writer to insert characters in Writer. See Help → OpenOffice Help → Index → AutoText.

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
djwebb1969
Posts: 7
Joined: Mon Mar 13, 2023 6:16 pm

Re: Macro to paste a specific character

Post by djwebb1969 »

Thank you ̇
Open Office 4.1.14, Ubuntu 20
User avatar
Lupp
Volunteer
Posts: 3693
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Macro to paste a specific character

Post by Lupp »

Though the thread is already marked SOLVED, I append this:

When using macros to support editing, the problem is often not in the writing (or probably recording) the macro, but in making it accessible in a suitable way.

Only under very special conditions the usage of macros for editing is recommendable.
Since I was somehow interested in the task, I wrote such a macro and a short explanation.

The attached example document is used as the macro container, and also customised with an additional toolbar for the access.

Of course, the macro doesn't exactly match the original topic. There is an older solution for this by the extension https://extensions.openoffice.org/de/pr ... characters and LibreOffice has an additional means (the Alt+X feature).

The assumed subject for my solution would be:
"How to put text ranges in brackets with the help of a macro?"
app112591_bracketing.odt
(44.37 KiB) Downloaded 33 times
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
djwebb1969
Posts: 7
Joined: Mon Mar 13, 2023 6:16 pm

Re: [Solved] Macro to paste a specific character

Post by djwebb1969 »

Thank you for that. Very useful.
Open Office 4.1.14, Ubuntu 20
User avatar
Lupp
Volunteer
Posts: 3693
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Macro to paste a specific character

Post by Lupp »

Off topic (no macros), but related:
editHelpersInHeaderAnchoredFrame.ott
(29.79 KiB) Downloaded 63 times
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Macro to paste a specific character

Post by JeJe »

Code: Select all

Sub Addquotes
dim vc
on error resume next
vc = thiscomponent.currentcontroller.viewcursor
vc.string = "‘" & vc.string & "’"
End Sub
You can use find/replace without a macro if what you want to surround with quotes is all in one paragraph

fandr.jpg
fandr.jpg (23.69 KiB) Viewed 2769 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Locked