I turned a GUI that I wrote in python into an executable via chmod +x mygui.py, added a shebang. Then I added this script to the "Session and Startup" list of programs (Settings -> Session and Startup) in order to run it when I turn on my computer. When I reboot my computer, the GUI is opened but some of its widgets are not drawn.

Edit: After opening the properties of a launcher I created on my desktop for the same python script, I realized that the difference is that the launcher has a "working directory" which the startup manager doesn't know about. I am pretty sure that this is the reason why some widgets aren't loading since they use some icons and other elements that are in the same directory as the script. So now my question is, how do I tell ubuntu where to look for everything in my script when it opens it on startup? Thank you.

  • What is the command in the launcher, and what is your command to run the application on startup? – Jacob Vlijm Aug 24 '15 at 19:48
  • 1
    I was able to fix it: I added the lines import os; os.chdir("/path/to/script") to __main__ and now when the startup manager runs my script, the working directory gets changed and everything works fine. Thank you! – Gustavo Rodriguez Aug 24 '15 at 19:50
  • I assumed it was in that corner :). You could also include the cd in the startup command: /bin/bash -c "cd /path/to/script && command_to_runit" – Jacob Vlijm Aug 24 '15 at 19:53

you can set "working directory" or in Linux term "path" in three different ways:

1) add your script PATH to environment variables. It's a fairly easier way and works good but it's permanent and it's not a good practice IMO. The way to do that is to issue this command:

export PATH=$PATH:your_path

2) add your script PATH to the shortcut .Just open the .desktop file in a text editor (if you're having trouble finding it, you can create the launcher on your desktop and find it in ~/Desktop, then move it later), and add a line at the end that says Path=YOUR_PATH. Then add the .desktop file to the startup

3) first go to your directory then start your script. for example:

bash -c "cd /path/to/directory && /path/to/directory/executable"
  • My launcher (the .desktop) works perfectly. What I am trying to figure out is how to give the startup application a working directory for the script that I am running on startup. The launcher asks for a working directory and a command to run, but the startup applications manager does not. I tried adding the path to my PATH variable on .bashrc and it still doesn't load the widgets or anything from the directory where the script is placed. – Gustavo Rodriguez Aug 24 '15 at 19:16
  • did you add the line path=/path/to/script in the .desktop file ? – AliReza Mosajjal Aug 24 '15 at 19:18
  • Yes - I'm sorry, I think I haven't been clear on my question (I edited it). I am not trying to fix the .desktop shortcut, that works perfectly. What I am trying to fix is the entry on the "Session and Startup" application. That entry is not linked to my .desktop, it is linked to my .py in the path where I created it. However, it knows where the script to run is, but it doesn't know the working directory for that script, which is why it can't load some of the things. Edit: I also tried to run my .desktop shortcut from the startup application since it worked so perfectly. It doesn't do anything. – Gustavo Rodriguez Aug 24 '15 at 19:23
  • have you tried the third option I listed ? navigate to the path then run the script like I said. although in your case it would look like this : bash -c "cd /path/to/exec && python script.py" – AliReza Mosajjal Aug 24 '15 at 19:27
  • I was able to fix it: Look at my comment on my first post. Thank you though! Your answer pointed me in the right direction and I was able to find a solution. – Gustavo Rodriguez Aug 24 '15 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.