Linux autostart on login

Run shell command exectly one time at login

I am on Ubuntu 18.04 and trying swap Ctrl and CapsLock using xmodmap . But failed to find a way of doing that automatically: .[X|x]modmap[rc] and .config/autostart didn’t work. What other ways are there? Could it be possible throgh systemd ? SHORT: Desktop entry in .config/autostart or /etc/xdg/autostart . Exec is not a full-fledged shell command, so sh -c might be required

[Desktop Entry] Type=Application Exec=sh -c "xmodmap ~/.xmodmaprc" 

I think you want the command to run when gdm starts (so is technically not part of the boot process).

Comments are intended to be helpful: to help you improve the question / answer. So don’t expect them to be an answer.

2 Answers 2

Since Ubuntu switched back from Unity to Gnome in version 17.10, you should be able to use the Gnome autostart mechanism (if it is sufficient that the shell command is launched on login).

  • you will need sudo privileges
  • create a shell script that runs the necessary command (say switch_ctrl_capslock.sh ) and place it in /usr/local/bin
  • create a .desktop file /etc/xdg/autostart/switch_ctrl_capslock.desktop with (more or less) the following content:
[Desktop Entry] Type=Application Exec=/usr/local/bin/switch_ctrl_capslock.sh 

If everything is setup correctly, the script should be run once when the user logs into Gnome.

For further reading, have a look at

Источник

How do I make a program auto-start every time I log in?

I frequently need to start several programs that I use every time I start my computer. How can I make it so that whenever I login the program is automatically launched?

@Kaustubh — it does. But I like generic questions rather than the same question asked multiple times with slightly different programs 🙂

8 Answers 8

To make a program start with Ubuntu:

  • If you’re using Unity, search for the program Startup Applications .
  • If you’re using Ubuntu Classic, it’s under Start Menu > Preferences > Startup Applications.

To make Ubuntu remember your running applications on shutdown:

enter image description here

  1. Open a terminal, and run gconf-editor .
  2. Navigate to /apps/gnome-session/options.
  3. Enable the option: auto_save_session.

(NOTE: this may slow system boot, and has not been throughly tested.)

i did that but like i remember in 10.10 it has a button that said click here to remember all applications open to be start up automatically (or something like that)

That post is from February when Natty was being tested. There is no other information that goes along with it, but I would assume they are still trying to fix it.

User defined sessions for applications to start after login

An alternative way to automatically start applications after login is to define a user defined session. This has the advantage to use different sessions for different task, each with different applications loaded.

For this purpose we create a custom.desktop file as root in /usr/share/xsessions with the following content (for GNOME/GDM):

[Desktop Entry] Name=Marco's Crowded Session Comment=Custom ~/.xsession script Exec=/home/username/.xsession X-Ubuntu-Gettext-Domain=gdm 

Use any fancy name for your session and replace username by your name of course.

This will run the script .xsession in the HOME directory at login where we can put in any appplications we need to start after login.

The script needs to be named as defined in the .desktop file, that is ~/.xsession in the example given, needs to be made executable and may have a content similar to this:

#! /bin/bash my-important-app [options] & second-app [options] & [. ] # add other applications gnome-session [options] 

Options for gnome-session may be omitted to load the default session. Give e.g. —session=classic-gnome as option to run Classic GNOME Desktop in 11.04.

Next time we login we will have the choice to start a «Marco’s Crowded Session» with all applications from the script running in addition to applications from the gnome-session (or any other desktop manager you chose to start here).

Starting other desktop managers

To start another installed desktop manager replace the last line from the ~/.xsession script with the following:

  • gnome-session —session=ubuntu for standard desktop (with Unity in 11.04).
  • gnome-session —session=classic-gnome for classic GNOME desktop.
  • startkde for KDE desktop manager.
  • startxfce4 for XFCE, or when running Xubuntu.

Источник

How do I start applications automatically on login?

15 Answers 15

20.04 and later

  1. If not yet done by default install gnome-startup-applications
  2. Search and open «Startup Applications» screenshot
  3. click add to enter the command including options of your application as you would run it from terminal (you may have to give in the full path if it runs from a non-standard location) screenshot
  • This will add a .desktop file in your ~/.config/autostart screenshot

14.04 and later

screenshot

  1. Open the Dash and search for «Startup Applications»
  2. Now click on Add and give in the command to run the application. This can be found in Main Menu if installed (see below)

Using Main Menu (alacarte) to find the terminal command to run a given program:

  1. Firstly open the program ‘Main Menu’ (type Menu in the Dash) screenshot
  2. Now select the program which you want to add to startup and click on properties . screenshot
  3. Now note the command for that program . screenshot

Non GUI approach

Advanced users may want to manually put a .desktop file in ~/.config/autostart to run applications after a user login. This may have following content:

[Desktop Entry] Type=Application Name= Exec= Icon= Comment= X-GNOME-Autostart-enabled=true 

You may have to give this file execute permission.

Источник

Читайте также:  Linux what java is installed
Оцените статью
Adblock
detector