[Solved] Macro: How to include paste from clipboard?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Joel_S
Posts: 6
Joined: Sun Sep 30, 2012 10:57 pm

[Solved] Macro: How to include paste from clipboard?

Post by Joel_S »

Hi!

I use bookmarks and cross references a lot, but there is a lot of manual steps each time I want to create them.

So I created a macro to automate the steps to create bookmark.
It copies the current selected text, moves back a couple of steps, opens "insert bookmark", paste the copied text, click ok.

The problem is with the "paste" operation - it doesn't paste, it enters the text that I pasted when created the macro.
So I want it do do the ctrl+v operation but it doesn't seem to record that into the macro.

Can I put in some code in the macro to perform the ctrl+v?

Here is the code that was generated for the macro. You can see where it says args4(0).Value = "cooltest" , it hardcodes my test string "cooltest" rather than performing the paste.

Code: Select all

sub create_curr_select_as_bookmark
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:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Count"
args3(0).Value = 1
args3(1).Name = "Select"
args3(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Bookmark"
args4(0).Value = "cooltest"

dispatcher.executeDispatch(document, ".uno:InsertBookmark", "", 0, args4())


end sub
Last edited by Hagar Delest on Sun Oct 03, 2021 8:39 pm, edited 1 time in total.
Reason: Tagged [Solved].
openoffice 3.4
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro - how to include paste from clipboard?

Post by JeJe »

Try

Code: Select all

sub create_curr_select_as_bookmark
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")

dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Bookmark"
args4(0).Value = thiscomponent.currentcontroller.viewcursor.string 
dispatcher.executeDispatch(document, ".uno:InsertBookmark", "", 0, args4())
end sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Joel_S
Posts: 6
Joined: Sun Sep 30, 2012 10:57 pm

Re: Macro - how to include paste from clipboard?

Post by Joel_S »

Thanks Jeje, it works!

Fantastic, this will save me a lot of time.
openoffice 3.4
Post Reply