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.
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 ).
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:
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With