Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

desktop application with gnome-terminal: relative paths to script and icon

I am using gnome-terminal to create a clickable desktop application. The application should be downloaded in a zip folder, with a sub-directory bin containing my myapp.desktop. I would like to have a different directory somedir in my zip file containing main application script and the icon for the application.

However, gnome-terminal does not seem to work with relative paths. Here my myapp.desktop:

[Desktop Entry]
Exec=gnome-terminal -e "bash -c -i 'exec $SHELL --init-file ../somedir/myscript.sh'"
Icon=../somedir/myicon.gif
Terminal=true
Type=Application

My question is: how can I pass the directory from which the application icon was clicked to gnome-desktop? Or how can I organize my directory such that I do not have to have myicon.gif and myscript.sh in the same directory as myapp.desktop?

I am aware of the --working-directory argument to gnome-terminal and tried to pass $PWD, without success.

EDIT:

Related question: Desktop Launcher for Python Script Starts Program in Wrong Path (Linux)

A path can be specified in the .desktop file, but again, it does not seem to deal with relative paths. If I add Path=., it is not found.

like image 498
user1981275 Avatar asked Dec 10 '15 15:12

user1981275


People also ask

Where is the path to the Applications directories in GNOME?

Bookmark this question. Show activity on this post. For shortcuts in the Applications drop-down Menu and on the title bar of the Gnome Desktop, where is the path to their directories? Show activity on this post. You are looking for the .desktop files, which are located in /usr/share/applications (or sometimes /usr/local/share/applications ).

How to create tabs in GNOME Terminal in Linux?

We can start it with the bash command gnome-terminal. We’re going to use version 3.40.3 throughout this tutorial. In some Linux distributions, gnome-terminal isn’t available out of the box, so we need to install it manually. 3. Creating Tabs in gnome-terminal With the –tab option, the gnome-terminal command creates tabs. So, let’s obtain two tabs:

Where can I find the desktop files in Linux?

You are looking for the.desktop files, which are located in /usr/share/applications (or sometimes /usr/local/share/applications). Some applications may place these files in ~/.local/share/applications instead.

Is a desktop file the same as a shell file?

However, a .desktop file is not the same thing as a shell, it is a plain text configuration file so it would not necessarily work the same way, even if .desktop files and shells can both be found on Linux If the name is an absolute path, the given file will be used.


2 Answers

Based on this document and other answers on ask ubuntu (like this or this), I think that you cannot use relative paths directly in the desktop application.

You can however keep your files in the desired folders and include in the package a configuration script that copy the executable and the icon in the default paths, as specified in the documentation ($PATH for the executable and /usr/share/pixmaps for the icon).

Also, here there is a nice workaround. And here a solution like the one I proposed.

Everyone seems to agree that it is not possible to use relative paths but ...

... searching a little bit more it seems that there is the possibility to use the home directory as the starting point for the relative path by leave out the forward slash on the path. Based on this page (link) this:

  Exec="${HOME}/bin/scripts/UNIX/Prototype.bash"
  Path=${HOME}/bin/scripts/UNIX

doesn't work

But this:

  Exec="Prototype.bash"
  Path=bin/scripts/UNIX

should.

like image 51
terence hill Avatar answered Sep 23 '22 19:09

terence hill


This method does not work because $PWD inside .desktop file, point to home directory.So you should create an installation script to generate "myapp.desktop" and copy both of "myapp.desktop" and "icon.png" to specific directory. copy this script to root of your app and run it!

install.sh

#!/bin/bash

home_local=$HOME/.local/share
icon_dir=$home_local/icons/hicolor/48x48/apps

myapp_desktop=$home_local/applications/myapp.desktop
myapp_dir=$PWD
myapp=$myapp_dir/bin/myapp.sh
myapp_icons=$myapp_dir/icons/myapp.png

echo "[Desktop Entry]" > $myapp_desktop
echo "Name=MyApp" >> $myapp_desktop
echo "Exec=bash -c 'cd $myapp_dir;bash $myapp;exec bash'" >> $myapp_desktop
echo "Icon=myapp.png" >> $myapp_desktop
echo "Terminal=true" >> $myapp_desktop
echo "Type=Application" >> $myapp_desktop

cp $myapp_icon $icons_dir 
like image 40
Sadegh Avatar answered Sep 21 '22 19:09

Sadegh