0

I would like to start python script in startup. Script changes wallpaper automatically every hour using feh --bg-max PATH/to/bg. Using Arch linux and qtile window manager. I've tried to execute it in .xinitrc before exec qtile start, but it crashes qtile. Then if I put it after it, script doesn't get executed. I've also set to startx run automatically on login. Python script works without problems if executed normally from terminal

Here is startx script:

#
# ~/.bash_profile
#
#Autostart x
[[ -f ~/.bashrc ]] && . ~/.bashrc
if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
    exec startx
fi




EDIT: the script i want to run:


import os
import time
import ctypes
import platform
import random


pictures = ["chemical_nord.png","ign_zorin.png","Nordic-Heroin.png","gnu-linux.png","linux-tux.png","nordtheme.png","Abstract-Nord.png","ign_nordhills.png","Minimal-Nord.png","qyqj7y34hlp31.png","archlinux.png","ign_unsplash10.png","nixos.png","waves.jpg"]


def get_wallpaper():
    number = random.randint(0,13)
    return number




def set_wallpaper():
    system_name = platform.system().lower()
    path = ''
    if system_name == "linux":
        number = get_wallpaper()
        path = "/home/My_Username/Pictures/"+pictures[number]
        command = "feh --bg-max " + path
        os.system(command)


if __name__ == "__main__":
    while(True):
        time.sleep(3600)
        set_wallpaper()



How to get it working?

3
  • Please also show us the script you want to run. Note that you cannot run it before launching the window manager since there will be no background for it to change. You will have t make it run after qtile.
    – terdon
    Jan 24, 2022 at 14:46
  • Thats is my question, how to run it after executing qtile start. What are other ways to do it other than in.xinitrc
    – user511488
    Jan 24, 2022 at 14:55
  • 1
    There should be a way of doing it by editing a startup script for qtile itself. Sorry, I've never used it, but search its documentation for something along those lines.
    – terdon
    Jan 24, 2022 at 15:06

2 Answers 2

0

In order to fire your script on startup either you could manually add it by going to /home/$USER/.config/autostart and create a .desktop file with the contents shown below:

[Desktop Entry]
Type=Application
Exec=command you wish execute on startup
Name=Name you wish to provide
Comment=comment to describe what the command does

Or, you could open Startup Application app in your linux distro if available and add a entry there by providing the necessary details.

0

If yours script depends on qtile you need to run it after qtile, with qtile autostart.

https://docs.qtile.org/en/latest/manual/config/hooks.html?highlight=autostart#autostart

    import os
import subprocess

from libqtile import hook

@hook.subscribe.startup_once
def autostart():
    home = os.path.expanduser('~/.config/qtile/autostart.sh')
    subprocess.Popen([home])

Any infinit loop process in .xinitrc needs & at the end of line so .xinitrc resumes without waiting it to finish.

For example ~/.config/qtile/autostart.sh

        ~/.scripts/my_script.py &
1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Aug 19, 2022 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .