Accessing a singleton

The type com.sun.star.frame.Desktop is deprecated, and it is recommended to use the com.sun.star.frame.theDesktop singleton instead.

How can I acces this (and other) singletons?

In Java, this thread says the following works:

com.sun.star.frame.theDesktop.get(componentContext)

However, the com.sun.star.frame namespace isn’t available under the Automation bridge; there is only the single entry point of the service manager:

var objServiceManager = new ActiveXObject('com.sun.star.ServiceManager');

hello Zev Spitz,

you need to get the Default Context from the ServiceManager, then call getName() with the singleton path as argument.

i do not know enough Java, but in Basic it would look like this, so you get the idea:

theDesktop = GetDefaultContext().getByName( "/singletons/com.sun.star.frame.theDesktop" )

Hope it helps, lib

I am not asking about Java, but rather using the Automation bridge. How do I get the script context via the Automation bridge?

The Automation bridge exposes the script context at the DefaultContext property on the service manager. Once we have the script context, we can use the getByName method, passing in the singleton path:

var serviceManager = new ActiveXObject('com.sun.star.ServiceManager');
var desktop = serviceManager.defaultContext.getByName('/singletons/com.sun.star.frame.theDesktop');

(I was led to the solution by this post where the author is trying to automate OpenOffice using Delphi.)

Question on StackOverflow