简体   繁体   English

Ubuntu-登录后如何运行python脚本?

[英]Ubuntu - How to run python script after logging in?

I created a simple python script to change my ubuntu wallpaper. 我创建了一个简单的python脚本来更改我的ubuntu壁纸。 I want to this script run after whenever I logged in. 我想在每次登录后运行此脚本。

  • I tried to add command in startup application as python /bin/wallpaper_changer.py but it doesn't work. 我试图在启动应用程序中将命令添加为python /bin/wallpaper_changer.py但它不起作用。
  • I also tried to add a desktop entry in ~/.config/autostart/Myscript.desktop but it also doesn't work. 我还尝试在~/.config/autostart/Myscript.desktop添加一个桌面条目,但是它也无法正常工作。
  • I also added this file path in crontab using sudo crontab -e @reboot python /bin/wallpaper_changer.py it also doesn't work. 我还使用sudo crontab -e @reboot python /bin/wallpaper_changer.py在crontab中添加了此文件路径,它也行不通。
  • I added entry in rc.local as python /bin/wallpaper_changer.py it also doesn't work 我在rc.local中添加了python /bin/wallpaper_changer.py条目,它也不起作用

Maybe this link will help you. 也许链接会为您提供帮助。 I prefer to put a start-up command in /etc/rc.local. 我更喜欢将启动命令放在/etc/rc.local中。 You can call it by typing on terminal sudo nano /etc/rc.local . 您可以在终端sudo nano /etc/rc.local上键入它来调用它。 You can also use crontab. 您也可以使用crontab。

I found solution for this. 我找到了解决方案。 first make your source file executable. 首先使您的源文件可执行。

chmod +x /path/to/your/file

after add it to cron tab. 将其添加到cron选项卡之后。

sudo crontab -e

If it asks for any editor choose editor options. 如果要求任何编辑器,请选择编辑器选项。 after it add your path when # symbols end. 在#符号结束时添加路径。

@reboot /path/to/your/file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM