I wrote a function for switching to the correct virtual desktop and
starting all the commands. I am also using with now:
def do_desktop(desktop, commands, seconds_to_wait = 10):
desktop_command = ('wmctrl -s ' + desktop).split()
check_call(tuple(desktop_command))
for command_arr in commands:
command = command_arr[0].split()
log_directory = command_arr[1]
directory = command_arr[2]
if (directory != ''):
chdir(directory)
if (log_directory == 'NONE'):
Popen(tuple(command.split()))
else:
log_file_name = log_directory.replace('%T', strftime('%F_%R'))
with open(log_file_name, 'w') as log_file:
Popen(tuple(command), stdout = log_file, stderr = STDOUT)
if (directory != ''):
set_default_dir()
sleep(seconds_to_wait)
The function set_default_dir:
def set_default_dir():
chdir(expanduser('~'))
The example with firefox is then done with:
commands = [
['firefox', 'Logging/firefox_%T.log', ''],
]
do_desktop('10', commands, 30)
Sometimes a command needs to be executed in a different directory,
that is done like:
commands = [
['lein run', 'NONE', 'Clojure/Quotes'],
['xfce4-terminal --maximize --execute screen -S Clojure -c ~/.screenrcClojure', 'NONE', ''],
]
do_desktop('6', commands, 30)