I'm trying to run a script on session start, so I added it to System -> Preferences -> Startup Applications.

The script does run, but some of the commands inside don't appear to run at all. If after startup I open a terminal and run the script manually, it runs fine!

#!/bin/bash
if [ "$DISPLAY" == ":0.0" ]; then
  tmux new -s Phys \; \
    new-window -t Phys -n synergy \; \
    send-keys -t Phys:1 '~/bin/start-synergy' 'enter' \; \
    send-keys -t Phys:0 'xbmc' 'enter' \; \
    select-window -t Phys:1
else
  tmux new -s NX \; \
    new-window -t NX -n miro \; \
    send-keys -t NX:0 'transmission-gtk' 'enter' \; \
    send-keys -t NX:1 'miro' 'enter' \; \
    select-window -t NX:1
fi

The only reason I'm using tmux is so I'd be able to see the console output, since I was having trouble making the script open the applications properly.

However, it doesn't work at all, tmux doesn't start.

As I said, if I open a terminal and run this script, then it does work perfectly!

I tried redirecting tmux' output to a log file to see if I got a clue there, but the log ends up empty.

Also, I added echo commands that output to a file, just to see if the script is being run at all, and it is.

What could be the cause?

link|improve this question

Startup applications are often given a minimal environment. Perhaps tmux is not in PATH at that point. Try using the full path to tmux. You might also try launching a simple X application such as /usr/bin/xclock or /usr/bin/xmessage and see if that works. – garyjohn May 10 '11 at 18:31
feedback

1 Answer

up vote 0 down vote accepted

It's possible that the script is being run before your path is fully set up. I generally make it a habit to use absolute paths to every command I run in a script specifically to avoid path problems.

Try changing tmux to /path/to/tmux; you can find this path easily by running the command whereis tmux. Do the same thing for you subcommands, too -- instead of ~/bin/start-synergy, for example, do /home/[your username]/bin/start-synergy, etc.

link|improve this answer
That, along with the fact that I don't know why sometimes $DISPLAY is :0.0 and sometimes it's :0 (just found that out through some tests). So using full paths plus "$DISPLAY" == ":0.0" -o "$DISPLAY" == ":0" as the condition solved my problem. Thanks! – Ivan May 10 '11 at 18:49
feedback

Your Answer

 
or
required, but never shown

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