Skip to content
Snippets Groups Projects
bashguide.jsx 80.4 KiB
Newer Older
Alexander Schoch's avatar
Alexander Schoch committed
        <code>sleep</code> pauses the execution of your script for a number of
        seconds. It basically takes a number as an argument, then does nothing
        for that number of seconds, and then returns. It can be useful if you
        want to make your script do something in a loop, but want to throttle
        the speed a little.
      </p>
      <pre>
        <code>
          # prints "Get back to work" once per second. {"\n"}# Note that 'true'
          is a command that always returns 0.{"\n"}while true{"\n"}do{"\n"}
          {"    "}echo 'Get back to work!'{"\n"}
          {"    "}sleep 1{"\n"}done
        </code>
      </pre>
      <p>
        <strong>mplayer or mpv</strong>
      </p>
      <p>
        <code>mplayer</code> and <code>mpv</code> are media players that can be
        used from the console. <code>mpv</code> is based on <code>mplayer</code>{" "}
        and a lot more modern, but they can do essentially the same.
      </p>
      <pre>
        <code>
          # play file "music.mp3"{"\n"}mplayer 'music.mp3'{"\n"}mpv 'music.mp3'
          {"\n"}
          {"\n"}# play file "alarm.mp3" in an infinite loop{"\n"}mplayer -loop 0
          'alarm.mp3'{"\n"}mplayer --loop=inf 'alarm.mp3'{"\n"}
          {"\n"}# play a youtube video{"\n"}# this only works with mpv and
          requires youtube-dl to be installed{"\n"}mpv
          'https://www.youtube.com/watch?v=lAIGb1lfpBw'
        </code>
      </pre>
      <p>
        <strong>xdotool</strong>
      </p>
      <p>
        <code>xdotool</code> can simulate keypresses. With this command, you can
        write macros that perform actions for you. It allows you to write
        scripts that interact with GUI programs.
      </p>
      <pre>
        <code>
          # press ctrl+s (in order to save a document){"\n"}xdotool key
          'Control+s'
          {"\n"}
          {"\n"}# type "hello"{"\n"}xdotool type 'hello'
        </code>
      </pre>
      {/* end pandoc */}
    </>
  );
}