起動時にPythonスクリプトを起動する

起動時にPythonスクリプトを起動する

起動時にPythonスクリプトを起動したいと思います。 1時間ごとに壁紙を自動的に変更するために使用されるスクリプトfeh --bg-max PATH/to/bg。 Arch Linuxおよびqtileウィンドウマネージャを使用します。.xinitrc以前に実行しようとしましたが、exec qtile startqtileがクラッシュします。その後、後に置くとスクリプトは実行されません。また、ログイン時に自動的に実行するようにstartxを設定しました。端末で正常に実行すると、Pythonスクリプトは正常に動作します。

これはstartxスクリプトです:

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




編集:実行したいスクリプト:


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()



どのように機能させるのですか?

ベストアンサー1

起動時にスクリプトをトリガーするには、次の内容を含むファイルに移動して/home/$USER/.config/autostart作成して手動で追加できます。.desktop

[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

あるいは、Startup ApplicationLinuxディストリビューション(利用可能な場合)でアプリケーションを開き、必要な詳細を提供してアイテムを追加することもできます。

おすすめ記事