Programmatically run at startup on Linux?

走远了吗. 提交于 2019-12-04 04:43:45

问题


How do I programmatically set an executable on Linux to run when the user logs in?

Basically, the equivalent of the HKCU\Software\Microsoft\Windows\CurrentVersion\Run registry key in Windows.


回答1:


For gnome on Linux, place a .desktop file referring to your application in ~/config/autostart/, the format is fairly simple:

[Desktop Entry]
Type=Application
Exec=foo
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=foo

and you will have to set the exec bit for this file (chmod +x)

If you are shipping on Linux, you should create one of these anyway and place it in the menus.

For KDE on Linux you should create a symbolic link to your program's executable in the folder ~/.kde/Autostart/




回答2:


If you don't have GNOME, you'd typically put your commands in a shell's .profile or .rc, or in startx if you want this to run in/before your X-environment. You could also hook something into your gdm scripts/.rcs or whatever login manager you have.



来源:https://stackoverflow.com/questions/3358300/programmatically-run-at-startup-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!