xsession startup scripts

Can someone please tell me how to run xsession startup scripts whenever I start or after I restart my X session? I'm not trying to do anything fancy I just want this to run. This makes life a lot easier when I use a dual monitor.

xrandr --output VGA1 --mode 1024x768 --rate 60

What's your window manager, if any?

I have both kde and gnome. Kde is my default one though.

KDE has autostart.

What about when I am not using the gui? Or if I want to use a system wide startup script? I don't always use the gui and I would like to create a few scripts that effect the whole system.

xrandr isn't going to do much when X isn't running.

You can try ~/.xinitrc, though I think some WM's ignore that these days. There might be a global equivalent of it under /usr/X11 somewhere though many X11 files aren't where they used to be these days.

As for general-purpose scripts to run on startup, see if your system has /etc/local.start or /etc/conf.d/local.start.

You can also put a line in a user crontab like @reboot /path/to/script.sh and cron will run it on poweron.

If X is being started from the console then usually startx is used which is a frontend to xinit which reads the system xinitrc and the user ~/.xinitrc. If using a graphical login manager this file is ignored. If using xdm, then usually it will read the system wide xsession and the user's ~/.xsession. The ~/.xsession file can simply be a symbolic link to ~/.xinitrc. If using another graphical login manager such as GDM or KDM, then the xsession file may not be read and the facilities provided by those login managers and the desktop environment or window manager must be used instead. I usually create a ~/.xinitrc and symlink it to ~/.xsession. If I then use a login manager that does not use ~/.xsession I use its autostart facilities at point it at it.

I do not have /etc/local.start or /etc/conf.d/local.start.

I already added my script to ~/.xinitrc with no luck.

Would this work? Would I need to add * in front of @reboot?

# m h  dom mon dow   command 
#44 4 27 5 4 /home/bob/Desktop/test
#* *    * * *   /home/bob/Desktop/yo
#0 * * * * echo hi >> /home/bob/Desktop/come
0 0 * * * /home/bob/Desktop/video
0 * * * * date >> /home/bob/.bash_history
#*/10 0-8 * * * /home/bob/Desktop/logout 
@reboot /home/bob/.xprofile

What if I don't have a ~/.xsession?