0

I'm created a .desktop file in ubuntu 12.04LTS to run my shell script in terminal directly. Its working fine, but I'm facing a problem, "/openlypsaa/" as username here, I want to capture home username and assign to path for "Exec" as dynamically. How can I handle this path dynamically with a variable or any another method? Please help me to solve this issue.

Here is my .desktop file content

    [Desktop Entry]
    Version=1.0
    Name=openLypsaa Installation Script
    Comment=Installation script for openLypsaa software.
    Exec=/home/openlypsaa/Desktop/ol_install_script/install.sh
    Path=/home/openlypsaa/Desktop/ol_install_script/
    Icon=/usr/share/icons/Humanity/apps/32/access.svg
    Terminal=true
    Type=Application
    Categories=Utility;Application;Development;
Arjun Pokkattu
  • 129
  • 2
  • 17

2 Answers2

3

You can use $USER in bash, which contains the logged in user's username.

 Exec=/home/$USER/Desktop/ol_install_script/install.sh
  • 1
    I tried, but it takes the path as $USER directly like this /home/$USER/Desktop/ol_install_script/. I think we can't use any bash variables in .desktop file, correct me if I'm wrong! – Arjun Pokkattu Nov 17 '13 at 07:37
  • This will work if combined with running in a shell, see here: https://stackoverflow.com/q/8980464/50385 – Joseph Garvin Dec 07 '18 at 16:21
0

I don't see the point of doing this. Just install the script to be run in a system-wide location such as /usr/bin. That will actually be easier for you.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • Dear Robin, I don't want to run this script from system-wide location, what I need is, a user can run this script in terminal directly by a double click. – Arjun Pokkattu Nov 16 '13 at 07:35
  • But WHY don't you want to run this script from a system-wide location? That is how you are supposed to do it. If you don't want to do THE THING THAT WILL ACTUALLY WORK, you need to explain WHY. – Robin Green Nov 16 '13 at 07:36
  • Please note, I am not telling you not to use a desktop file, I am telling you to install the script in `/usr/bin`, and then use `/usr/bin/ol_install_script` or whatever as the location in the `.desktop` file! – Robin Green Nov 16 '13 at 07:38
  • I just wanna run the script directly in terminal from a user click. No user need to select "run in terminal" option when click this script file. That's why I am using .desktop file. – Arjun Pokkattu Nov 16 '13 at 07:59
  • Please read my previous comment. I AM NOT TELLING YOU NOT TO USE A DESKTOP FILE. YOU CAN USE A DESKTOP FILE, NO PROBLEM. YOU JUST HAVE TO PUT THE SCRIPT IN /usr/bin. – Robin Green Nov 16 '13 at 08:00
  • Im already programmed in this script that the location must from '/Desktop/ol_install_script/'. So, if I putting my entire scripts in '/usr/local/bin' it may effect the path used in each related scripts. – Arjun Pokkattu Nov 16 '13 at 08:08
  • A common solution to this problem is to make the installation process (e.g. `make install`) substitute a special string (such as `INSTALL_DIR`) with the actual installation directory - in this case, `/usr/local/bin`. – Robin Green Nov 16 '13 at 08:12
  • I'm trying your solution – Arjun Pokkattu Nov 16 '13 at 08:16