How can one run a shell script just before the desktop session begins?

Rather than executing the script before session begins, you can execute it as soon as session begins. For an end user, this does not make difference as scripts would have started executing when you see your session.The steps are as follows.

  1. Create a shell script and provide it necessary permissions.

  2. Open startup applications by searching in dash or your menu, depending on your OS.

  3. Click on Add. enter image description here

  4. Give a name and add the command, which would be location of your script.You may also add a optional comment.
    enter image description here

  5. Click on add, ensure that script is selected and then close the window.

Next time the script would be executed on startup.