I would like to make a Python 3.4 script that starts with my computer so that it's permanently checked to start up with the computer (edit: permanently checked means it can't be disabled via xfce4-session-settings). (Edit: This should affect all users, even future ones, but if you answered before I said this, I won't factor that in to whether I accept it.) The script does not need to end, particularly. I don't want unprivileged users to be able to uncheck it. How would I go about doing this?

Currently, they can't delete or edit (or even view the details) the entry (thankfully), because it's made for all users (even future ones). However, they can uncheck it just fine, it seems.

(I enabled it for set for all users by adding a myScript.desktop file to /etc/xdg/autostart and gave it the following text:

[Desktop Entry]


The script allows my IP address for a dns-based web filter to be updated. It periodically checks for a lost connection in case the router was reset and the IP address changed.

I'm on Xubuntu 14.04, 64-bit.

  • ...might want to try and hide it with NoDisplay=true. – mikewhatever Aug 30 '14 at 17:02
  • I believe that's supposed to work, but it was still on the list after a reboot. – Brōtsyorfuzthrāx Aug 30 '14 at 18:53
  • The list being the list of programs that autostart as seen in xfce4-session-settings. – Brōtsyorfuzthrāx Aug 30 '14 at 19:00


I think you're looking for an 'init script' solution. There is a simple example here: https://unix.stackexchange.com/questions/6697/run-python-script-on-startup and another one here: http://mobiarch.wordpress.com/2014/05/16/creating-an-init-script-in-ubuntu-14-04/

Briefly: You put your script to e.g. /usr/local/bin/my_script.py (it's not necessary, you can run it even from your home dir)

Don't forget to:

sudo chmod +x /usr/local/bin/my_script.py

Next, in /etc/init.d you create a file e.g. my_script with the following content:

# /etc/init.d/my_script
# Description: Starts Python script my_script
# ————————————————–
# Provides: my_script
# Required-Start: $network $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start Python script my_script

case $1 in
    echo -n "Starting my_script: "
    /usr/bin/python /usr/local/bin/my_script.py &
    echo "Usage: my_script start"
    exit 1

Since you want this script to start on startup run this command:

sudo update-rc.d my_script defaults

I'm not sure if I get your point with "I need it to start the script after Python 3.4 becomes available, as it's a Python script;". Please try this way and let me know if it starts or not.

Edited again... Anyway I was thinking about it... If your python script cannot be started until some uncertain event maybe you can just create a simple bash script... something like that:


while [ $STARTED == 0 ]
    ./myscript.py && STARTED=1
    sleep 1
| improve this answer | |
  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Parto Aug 30 '14 at 18:41
  • Okay, I need more help. I need it to start the script after Python 3.4 becomes available, as it's a Python script; and I don't want to end it at all (except on shutdown or reboot). What should I do? What do I have to put in my script in addition to my script in order to use your advice? – Brōtsyorfuzthrāx Aug 30 '14 at 18:56
  • I'm checking out the edit now. (I didn't realize it was edited in my comment on your other question.) – Brōtsyorfuzthrāx Sep 1 '14 at 23:00
  • For the bash script, how would I autostart it (without it going in the xfce4-session-settings)? That's pretty much what I want to know. (Still checking out the rest of your edit.) Could I put it in /etc/init.d/ and do the same process with it as with the conf files? I know how to autostart bash scripts regularly, though. (I just don't want the script to show up on the list of autostart programs.) – Brōtsyorfuzthrāx Sep 1 '14 at 23:03
  • Okay, I think it's true that Python isn't available when the script executes. However, a regular bash script would probably work. I think your method involves executing the script before a user logs in. Is that right? I'd like to have it begin afterward (and have it continue afterward). However, I think your bash suggestion will work, and I don't have a lot of energy to devote to this topic (especially as the computer I was working with is out of my hands). So, I'll accept your answer, for now. If it doesn't work, try my answer (people reading this), which though not ideal, certainly works. – Brōtsyorfuzthrāx Sep 1 '14 at 23:35

Another solution that I used is based on Upstart, a quite powerful stuff. Maybe you don't need it at all. http://upstart.ubuntu.com/cookbook/

Let's create a file in your home /home/your_user_name/scripts/my_script.conf with this content:

# my_script.conf

description "here goes the description for my_script"
author "Peter Farkas @ InDaLine"

# Stanzas
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Run before process
pre-start script
   setuid pep
   chdir /home/your_user_name/scripts
end script

# Start the process
exec /usr/bin/python /home/your_user_name/scripts/my_script.py & 

# Run after process start
post-start script
    echo "my_script.py started"
end script

We need to make it executable:

sudo chomd +x /home/your_user_name/scripts/my_script.conf

After that link this .conf file into the /etc/init directory:

sudo ln -s /home/your_user_name/scripts/my_script.conf /etc/init/my_script.conf

As I can remember after these steps my script started after each reboot and restarted if some error occurred. As I think you may not want your script to run forever so you don't need the respawn part in this file, but maybe this is exactly what you need so I just left there. (My script is intended to run forever and if it stops somehow it needs to be restarted immediately).

I'm still not sure about your sentence "I need it to start the script after Python 3.4 becomes available, as it's a Python script;" but Upstart is called itself "event based" so you may need that for fine tune the starting conditions...

| improve this answer | |
  • About the Python 3.4 note you mentioned, I just heard that it might not be available in init.d scripts or something. I don't know if that's true. Perhaps not. Anyway, the script should run during the whole session. This is because if the router is unplugged, and plugged back in, the script needs to help update the IP address again (since it changes). This looks like it could work, but it looks like it's specific to a specific user. Is that right? However, if we could make it so new users automatically have that configuration (which sounds possible), that would be great. I'll have to research. – Brōtsyorfuzthrāx Sep 1 '14 at 22:08
  • To be fair, I never mentioned the way it should work with multiple users. So, I'll test your code, and see if it works. – Brōtsyorfuzthrāx Sep 1 '14 at 22:16
  • I tried your suggestion without using upstart and nothing happened. I just had a script that writes a file (no file was written), as well as one that just pops up a tkinter showinfo prompt (no prompt). I would upvote you on both answers for the extra knowledge, persistence, and for the note about upstart, but my reputation on askubuntu isn't high enough, yet. – Brōtsyorfuzthrāx Sep 1 '14 at 22:54
  • I didn't do anything like sudo update-rc.d my_script defaults if I was supposed to, though. – Brōtsyorfuzthrāx Sep 1 '14 at 23:08

Well, I've found a crazy workaround. So, I thought I'd share. I'm not expecting it to be the accepted answer, however (but it works). It may or may not be dangerous.

That is to copy xfc4-session-settings from /usr/bin into the bin folder of all the users that I actually want to be able to use it (e.g. /home/sally/bin). Then, delete it from /usr/bin. Then, change permissionson the home bin directories so that unauthorized users can't access them. So, all future users can't see what autostarts. The drawback is they can't see any of it (although it's good they can't see the script). Keep a copy to put it back if you ever really need it there. Reboot (if the bin folders weren't already there).

I tried merely changing the permissions on it before I tried deleting it, but it still managed to open for users that shouldn't have had access to it.

| improve this answer | |

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.