Search code examples
bash

Can I make a file that opens a .mp4 and a few other bash scripts at the same time?


I want to make a .sh file that opens a music video, minimizes the videos window, and opens 3 new terminals with commands running in each of them. So far I have this:

#!/bin/bash
cd Videos
mplayer (videoname).mp4 & bg &
gnome-terminal -x cd & cd (program directory) & (command)
gnome-terminal -x cd & cd (program directory) & (command)
gnome-terminal -x cd & cd (program directory) & (command)

The terminals keep saying child something and the video window isn't minimized. Can you help?


Solution

  • Here are some of the problems with your script (so far)

        mplayer videoname.mp4 & bg &
    
    1. The bg & is unnecessary because the & in mplayer videoname.mp4 & says to run the command in the background.

    2. The bg & is meaningless anyway. The bg command says to run the most recently interactively stopped subprocess for the script in the background. There can't be any interactively stopped subprocesses ... since this is script. And running bg in the background is doubly meaningless.

    3. You seem to think that running in the background and minimizing are the same thing. They are not.

      Forcibly minimizing a window from a script is a bit tricky; see https://askubuntu.com/questions/4876/can-i-minimize-a-window-from-the-command-line/904558#904558

    Then this:

        gnome-terminal -x cd & cd (program directory) & (command)
    

    That looks so garbled it is hard to make out what you are actually trying to do. But I suspect you are trying to run a terminal in which you run cd somedir; somecmd. Doing that requires a subshell; e.g. something like this

        gnome-terminal -e '/bin/sh -c "cd somedir; somecmd"' &
    

    Note that the correct placements of the quotes in the above is critical.