LibreOffice Restart command

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

LibreOffice Restart command

Post by gkick »

Hi all,

Whenever some settings like eg language changes, LO displays a Restart message, goes down and restarts with the last file. Anyone knows the corresponding command for a macro?

Thanks
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: LibreOffice Restart command

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: LibreOffice Restart command

Post by gkick »

Thanks JeJe,

does this mean I need to import"XRestartManager.idl"; into the odb and then just call the function via a sub ?

cheers
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: LibreOffice Restart command

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: LibreOffice Restart command

Post by gkick »

@JeJe ,thanks for that, rolling up my sleeves.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
roland65
Posts: 32
Joined: Tue Oct 18, 2011 6:41 pm

Re: LibreOffice Restart command

Post by roland65 »

Since I needed this feature too, here is a macro for BASIC that restarts LibreOffice.

Code: Select all

' Restart LibreOffice
' 28/02/2023
Sub RestartLO

	Dim Context as Variant
	Context = GetDefaultContext()
	
	Dim RestartManager as Variant, Handler as Variant
	RestartManager = Context.getValueByName("/singletons/com.sun.star.task.OfficeRestartManager")
	
	If Not RestartManager.isRestartRequested(False) Then
	    
	    ' Avoid error "The window cannot be closed while BASIC is running"
	    On Error Resume Next
	    
	    ' Restart LibreOffice
	    RestartManager.requestRestart(Handler)
	
	End If

End Sub
LibreOffice 7.5.x on Ubuntu
Post Reply