Ask Your Question
0

macro: website lookup via system browser

asked 2016-07-20 14:30:52 +0200

paul1149 gravatar image

Now that LO has customizable context menus (5.2), we are open to conveniently adding website lookups! I pieced together this macro for a dictionary lookup:

Sub Dictionary_Lookup ' TFD
    Dim SysShell As Object
    Dim oCursor, oSeL
    oCursor = ThisComponent.CurrentController.ViewCursor
    oSel = oCursor.getString()

    SysShell = createUNOService("com.sun.star.system.SystemShellExecute")
    SysShell.execute("/usr/bin/flashpeak-slimjet", "www.thefreedictionary.com/" & oSel, 0)  
End Sub

I would be open to any suggestions for improving the macro. In particular, I would like to know how to call the system browser rather than spec the browser path, if that is possible. I'm on Linux.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-07-22 22:34:32 +0200

mark_t gravatar image

On windows, using SystemShellExecute where the URL is passed as the first argument the web page will be opened using the systems default web browser.

Not sure if this works on Linux, may be worth a try.

Sub Dictionary_Lookup
Dim oCursor, oSeL
Dim Result As String  

oCursor = ThisComponent.CurrentController.ViewCursor
oSel = oCursor.getString()
Result = replace(oSel, " ", "+")
SysShell = createUNOService("com.sun.star.system.SystemShellExecute") 
SysShell.execute("www.thefreedictionary.com/" & Result, "", 0) 
End Sub
edit flag offensive delete link more

Comments

@mark_t didn't work on Linux. Thanks for replace though - could not remember.

Ratslinger gravatar imageRatslinger ( 2016-07-22 22:50:56 +0200 )edit
1

How about xdg-open? SysShell.execute("SysShell.execute("xdg-open","www.thefreedictionary.com/" & Result, 0) or Shell "xdg-open http://www.thefreedictionary.com/" & Result Reference http://www.dwheeler.com/essays/open-f...

mark_t gravatar imagemark_t ( 2016-07-22 23:05:30 +0200 )edit

Shell "xdg-open http://www.thefreedictionary.com/" & Result works. Thanks for the info.

Ratslinger gravatar imageRatslinger ( 2016-07-22 23:34:07 +0200 )edit

Awesome, Mark. I'm using the xdg-open command, and I find the createUNOService is not necessary. Thanks.

paul1149 gravatar imagepaul1149 ( 2016-07-23 03:09:36 +0200 )edit
1

answered 2016-07-22 20:00:10 +0200

Ratslinger gravatar image

updated 2016-07-22 21:56:56 +0200

Just tried this - LO v5.1.3.2, xubuntu 16.04, Firefox 47.0:

Sub Dictionary_Lookup
Dim oCursor, oSeL
oCursor = ThisComponent.CurrentController.ViewCursor
oSel = oCursor.getString()
Shell "firefox http://www.thefreedictionary.com/" & oSel
End Sub

Also tried other sites and all worked OK.

Edit: When multiple words are to be selected, this dictionary site needs words joined by + sign. This modified macro adjusts for that:

Sub Dictionary_Lookup
Dim oCursor, oSeL
Dim Result As String  
oCursor = ThisComponent.CurrentController.ViewCursor
oSel = oCursor.getString()
Result = join(split(oSel, " "), "+")
Shell "firefox http://www.thefreedictionary.com/" & Result
End Sub

The selected string is examined for spaces and replaces with the plus sign. Other sites may need similar modifications depending upon the requirements.

edit flag offensive delete link more

Comments

Thanks you, Ratslinger. Appreciate you taking a look at this.

Your macro is quite a bit more streamlined than my attempt. It seems to have a problem with multiple-word phrases, though. In that case it opens the first word at thefreedictionary, and the second work at its own .com site. For instance "Happy childhood" goes to the happy definition at TFD, and to childhood.com. It does a similar thing using the Vivaldi browser, though the second tab does not get .com appended to it.

Thanks again

paul1149 gravatar imagepaul1149 ( 2016-07-22 21:17:42 +0200 )edit

Had not looked at multiple words - will try and get back if any success.

Ratslinger gravatar imageRatslinger ( 2016-07-22 21:32:12 +0200 )edit

Very nice, Ratslinger. Thanks very much.

Paul

paul1149 gravatar imagepaul1149 ( 2016-07-22 22:06:19 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-20 14:30:52 +0200

Seen: 998 times

Last updated: Jul 22 '16