0

我正在使用 Python 为 Ubuntu 创建一个背景更改器,主要是为了好玩。当我从 shell 运行脚本时,它会工作并在某个文件夹中的图像之间交替背景。现在我正在尝试通过 .profile 运行脚本,以便它在登录时运行。脚本肯定在运行——我在相关函数中放了一个打印语句,当我点击'alt、ctrl、f3'时,我看到了打印语句的输出——但无论出于何种原因,当该函数以这种方式调用。我认为从非本地目录运行它也不是问题——正如我所说,如果我运行'python program/python/desktop_changer/main.py',桌面转换器运行得很好。

以下是函数的相关部分:

if __name__ == "__main__":
    time.sleep(15)
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    while True:

    #Set pic, set timer, run continously
    for img in os.listdir('pics/'):
        #This next line is functional when I hit 'alt, ctrl, f3', outputting the paths for new images every ten seconds
        print(os.path.abspath('pics/' + img))
        set_gnome_wallpaper(os.path.abspath('pics/' + img))
        time.sleep(float(10))

和 set_gnome_wallpaper():

def set_gnome_wallpaper(file_path):
    command = "gsettings set org.gnome.desktop.background picture-options 'zoom' && gsettings set org.gnome.desktop.background picture-uri file://'%s'" % file_path
    subprocess.call(command, shell=True)

在 ~/.profile: (SPE 和 20 是不相关的参数,它们的用途被注释掉,直到我能正确运行)

python /home/chessie/program/python/desktop_changer/main.py SPE 20 &
4

0 回答 0