1

On Linux Mint 19 (all "dot" versions), there is an option to add "Start-up applications".

There, I've added the following script:

#!/usr/bin/env sh

export DISPLAY=:0.0
/usr/bin/thunderbird &

sleep 2

export DISPLAY=:0.0
/usr/bin/google-chrome-stable &

sleep 2

export DISPLAY=:0.1
env WINEPREFIX="/home/<user>/.wine" wine C:\\windows\\command\\start.exe /Unix /home/<user>/.wine/dosdevices/c:/ProgramData/Microsoft/Windows/Start\ Menu/Programs/Notepad++.lnk &

The goal of the script is simple:

  • Start Thunderbird on the 1st display
  • Start Google Chrome on the 1st display
  • Start Notepad++ on the 2nd display

Everything works fine, except that Notepad++ doesn't start.

What I've tried so far:

  • Change the order - Simply stopped everything from working
  • Reduce the sleep time - Doesn't change the behaviour
  • Check the logs - Can't find anything (using gnome-system-log and the included log viewer) about the file being executed or startup programs
  • Run the command directly in the shell - Works flawlessly
  • Change #!/usr/bin/env sh to #!/usr/bin/env bash - Doesn't change the behaviour

Is there anything else I can try?

  • Does the command line for Notepad++ work outside the script? Do you have a .desktop file for it? – ajgringo619 Jan 7 at 17:28
  • "Run the command directly in the shell - Works flawlessly" <-- yup, and yup. That's where I took the command from. From the .desktop file. – Ismael Miguel Jan 8 at 0:42
1

Okay, this was harder than I thought.

The problem was simple: it was the export DISPLAY=:0.1 that caused the issue.
This is an attempt of the 3rd item in the list: Start Notepad++ on the 2nd display.

After digging, I found the following post: Window placement when switching to multiple monitors (Which links to https://icyrock.com/blog/tag/xdotool/).

In the end, my file now looks like this:

#!/usr/bin/env bash

env WINEPREFIX="/home/<user>/.wine" wine C:\\windows\\command\\start.exe /Unix /home/<user>/.wine/dosdevices/c:/ProgramData/Microsoft/Windows/Start\ Menu/Programs/Notepad++.lnk &

sleep 1

export DISPLAY=:0.0
/usr/bin/thunderbird &

sleep 1

export DISPLAY=:0.0
/usr/bin/google-chrome-stable &

sleep 3

# move to 2nd monitor
# https://icyrock.com/blog/tag/xdotool/
# https://unix.stackexchange.com/questions/96066/window-placement-when-switching-to-multiple-monitors

wid=`xdotool search --name Notepad++|head -1`
max_state=`xprop -id $wid _NET_WM_STATE`

wmctrl -ir $wid -b remove,maximized_vert,maximized_horz
eval `xdotool getwindowgeometry --shell $wid`

new_x=1600
if [[ "$X" -ge "$new_x" ]]; then
  new_x=0
fi

xdotool windowmove $wid $new_x $Y
if [ -z "${max_state/*_NET_WM_STATE_MAXIMIZED_*/}" ]; then
  wmctrl -ir $wid -b add,maximized_vert,maximized_horz
fi

xdotool windowraise $wid

And everything is working fine now.

Notepad++ is now the first one to start, to give it time to initialize, and then moved to the 2nd display.

0

I do something similar on my Mint PC, although I run this script manually after I login. I found it was easier to use xdg-open with the .desktop files; that way, if the command ever changed, my script would still work. Also notice that I do not need to specify back-grounding of the command (with the &):

#!/bin/bash

#### This script configures my desktop and other settings ####

SYSTEM_DIR=/usr/share/applications
USER_DIR=$HOME/.local/share/applications

#### Start my preferred programs ####
xdg-open $SYSTEM_DIR/google-chrome.desktop
xdg-open $USER_DIR/org.gnome.Evolution.desktop
xdg-open $SYSTEM_DIR/homebank.desktop
xdg-open $USER_DIR/org.libreoffice.LibreOffice.desktop
xdg-open $USER_DIR/virt-manager.desktop
xdg-open $USER_DIR/rhythmbox.desktop
xdg-open $SYSTEM_DIR/FAHControl.desktop
#### End start preferred programs ####

You may want to throw in a minor delay at the beginning of the script, in case it takes your system a bit to finish logging in.

  • I will test this out and vote accordingly in 8-9 hours. I do have a 10 second delay before it starts. I will try this approach and give you feedback. – Ismael Miguel Jan 8 at 1:18
  • Sadly, it didn't work. It simply opened the .desktop file in the text editor. But I've managed it. – Ismael Miguel Jan 8 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.