1

I am trying to get a shell script to launch a browser. When run standalone, this script successfully opens a browser with

xdg-open http://localhost:8080

However, I am trying to make it convenient newbie-friendly, so I've created a .desktop file which launches this script (linuxStart.sh)

Here's the .desktop file

[Desktop Entry]
Type=Application
Terminal=true
Name=Start Application
Icon=utilities-terminal
Exec=./linuxStart.sh
Categories=Application;

So far so good. But when run this way, it seems xdg-open does not run, and the browser does not open. The command is ignored inside the script. What gives?

I have tried inserting

#!/usr/bin/env xdg-open

on top of the .desktop file with no effect

Here is linuxStart.sh (proof of concept)

#!/bin/sh

#Other commands (runs fine)
#...

#Does not run from the .desktop file
xdg-open http://localhost:8080

Thanks

OS: MX Linux 19.04

DE: Xfce

8
  • Likely impossible to answer without knowing how you are "running" the .desktop file and, maybe, what the content of linuxStart.sh is, but your issue is most likely related to Exec=./linuxStart.sh: the Desktop Entry Specification states that the Exec key must be either a full path or a name, which is in turn searched for in your PATH. Does the directory that contains linuxStart.sh appear in your PATH?
    – fra-san
    Sep 18, 2021 at 16:06
  • Thanks. No, it's not in my path. The idea is to make a portable app for linux (for DokuWiki). Since it should be run from Dropbox, USB, etc. (and be user-friendly) I cannot use the full path. The command however executes fine, it simply ignores the xdg-open command. I'll post the linuxStart.sh as well.
    – Real
    Sep 18, 2021 at 16:15
  • Thank you for you edit. I wouldn't know how it's supposed to work on MX Linux/Xfce but, on Arch Linux + KDE, Exec=./foo only works if foo can be found through a PATH search. So (based on the aforementioned Desktop Entry Specification) I'm reasonably sure Exec=./foo isn't portable. (How should the program interpreting the .desktop file guess the actual path . is meant to refer to? Note that .desktop files are also used by menus and launchers, which generally won't have an intuitive concept of "current working directory").
    – fra-san
    Sep 18, 2021 at 16:50
  • 1
    That said, trying to be more helpful with the issue you describe: how are you detecting that xdg-open http://localhost:8080 is not executed, while others command are? Are you watching the script running in a terminal emulator? Do you get any error message?
    – fra-san
    Sep 18, 2021 at 17:09
  • I got it working!! I simply removed Terminal=true. It seemed to launch a separate X terminal and mess things up. I did not see any error messages. Can you reproduce on Arch? Thank you!
    – Real
    Sep 18, 2021 at 17:30

1 Answer 1

2

By removing Terminal=true the file now seems to run. The user does need to set all files executable for this to work (which is ok I guess). It open with double click in Thunar.

#Works fine
[Desktop Entry]
Type=Application
Name=Start Application
Icon=utilities-terminal
Exec=./linuxStart.sh
Categories=Application;

It seemed to be launching another X terminal which was causing problems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .