Ubuntu desktop script to open terminal, navigate to a folder and run compass watch

15,810

Either you make a shell script (.sh file, don't forget to make it executable) or you make a desktop file (.desktop). Either of those can be double-clicked, although the former might bring up a dialog asking whether you want to execute it (can be configured, but only per user, IIRC).

myscript.desktop:

[Desktop Entry]
Exec=bash -c 'cd /var/www/myproject && compass watch'
Name=myscript
Terminal=true
Type=Application

(Note the Terminal=true part.)

myscript.sh:

#!/bin/sh
gnome-terminal -e 'cd /var/www/myproject && compass watch'

(Assuming you want to use GNOME Terminal.)

Of course, there are numerous other options.

Share:
15,810
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have tried to search for a simple answer for running a simple script (myscript.sh) from the Ubuntu (13) desktop that would open the terminal, navigate to a folder (/var/www/myproject) and then run the "compass watch" command (and then stay open). First I thought this would be very simple to accomplish, but after several fails and searches, this particular task/script seems overwhelmingly hard to get to work.

    To do this manually is not a big task:

    • Open terminal
    • navigate "cd /var/www/myproject"
    • run "compass watch"

    I thought this would be a walk in the park (although I am quite new to terminal and scripting), but through the searches I got some weird desktop launcher answers and complicated bash scripting functions solutions for sub-shell work-a-rounds. My question is, can this be done with one single (simple) file that is launched from the desktop?