What you're asking is very doable. Use
xev to display key codes when you press buttons and then
xmodmap to modify your key mapping.
The script to launch based on your request could easily be written in bash. I'd recommend writing a kill_wait() function which kills a process with SIGTERM and waits for that process to actually exit before continuing the script. It could look something like this....
Code:
function kill_wait() {
kill -15 $1
while [ ! -z "$(ps aux | awk '$2 == "'$1'" {print $0}')" ];do sleep 1;done
}
#Usage:
# kill_wait PID
#Where PID is an integer of the process id.
Note: my above kill_wait function is completely untested.
You'll have to use the ps command with other tools like grep or awk or what have you to determine if a program is running. Steam and plex should shut down gracefully with SIGTERM and the wait ensures that the program gets a chance to completely shut down before it starts another.
edit: here's a decent resource on how to
map keys to a script. I'd like you to note that if you're modifying the key configuration of your controller I'm not sure how it will behave with the default behavior of Steam and having input being captured. Also, I'd recommend breaking your logic down into a couple of scripts to be launched using keys on the remotes. However, I don't think a single script would be too hard either.
Source for coming up with answer. I've used xev before customizing keyboard shortcuts for my openbox interface. It's quite handy.
SAM