Is it possible to launch a program from a link in a document?

Hi,

I’m trying to launch a program from a link in a document. I’ve tried clicking the add url button, selecting document (not URL) then typing out the full path to the piece of software but when I click the link it opens in my distribution’s default text editor. I’d like to launch Chrome, which is installed but NOT the default selected browser for the system from a link in a document. Is this even possible? If so how would I go about doing it?

Thanks

Hello unholymachine, you could do this with a macro calling the Shell() function.
The precise command depends on your Operating System:

on Unix it would be Shell( "chromium-browser " + yourURL )

on Windows it would be Shell( "chrome:\\newtab " + yourURL )
( not tested)

I still get an error of:

“shell(%2522google-chrome-stable%2522)” is not an absolute URL that can be passed to an external application to open it.

With or without the addition of a ‘+’ and a valid url.

Btw, this is all under linux on LibreOffice 5.1.6.2

try to run this macro, does it give an error?

Sub Test
	Dim strURL As String
	strURL = "https://ask.libreoffice.org"
	Shell( "google-chrome " + strURL )
End Sub
1 Like

I’ll confirm @librebel answer:

Shell "google-chrome-stable https://ask.libreoffice.org/c/english/5"

Set FireFox as default for test. Opened link in Chrome. Also reversed test with Chrome & used firefox and no problem. This on Mint 18 system with LO v5.3.2.2 (have done similar with other LO versions - even back to v4.x).

On Linux clicking on a hyperlink runs /usr/bin/x-www-browser with the link target as the first argument. One can edit this script to handle various file types as desired. For example, to open PDF files with kpdf and everything else with chrome one could use:

#!/bin/bash

if [[ $1 == *".pdf" ]] 
then 
	kpdf "$@"
else
	/opt/google/chrome/chrome "$@"
fi
1 Like

At least on Win you can do that without writing user code by assigning a hyperlink to a textportion giving the executable as ‘Internt Path:’ in the file:/// notation. Example:
file:///C:/Program Files (x86)/Maxima/wxMaxima/wxmaxima.exe
which works on my computer. You may include parameters.

Well, the executable is not actually “in the internet”, but it surely is not found in the document.

In Linux, the same syntax works for me as well. For example, to run RStudio with the project file (*.Rproj), have to declare the path as a document file in the following way:
file:///media/antoni/WBT/Programs/WBT.Rproj
Extension “Rproj” is associated with the RStudio executable at the installation.

In linux it opens executables like *.sh files in a text editor, photos in a photo viewer, archives like *.zip in an archive manager, music files in a music box app, but I couldn’t get it to execute anything directly.

But under Further Settings you can select Form: Button. This creates a button, then toggle design mode and select the button and open the properties and edit the Events. Add an event for Mouse button pressed which calls something like this basic code:

Sub Main
	Shell("/usr/bin/google-chrome-stable %U")
End Sub

You may have to adjust the URL to fit w/ your system.

I’m glad I bothered testing before saying: using /usr/bin/env google-chrome-stable %U doesn’t work, it just doesn’t execute Chrome although the LED indicates else.

;-), Works for me. But I did say,: “You may have to adjust the URL to fit w/ your system.” Also you might want to adjust any suffix. The “%U” is for my Debian Linux Cinnamon OS. I expect this will be heavily OS dependent.