Simple little Rofi script!

With Arch Linux being my main operating system, and i3wm being my window manager of choice, it kinda made sense to start using Rofi for things like program launching, since it’s a basic menu application at it’s core. Lately I’ve been starting to realize the core of something like Rofi isn’t the best thing, and it’s well worth trying to customize and build your own scripts for things, if that’s what a program is fully built for. While digging through the configuration files for Rofi I noticed a few other menus for SSH, and a different run menu option, so I delved further, and actually spent quality time inside the man pages of the program, and learned enough about the program to make at least this work for me.

I would like to now, after many hours of thinking, and deliberating on how to impliment what I found into a thing to help make my life even…. lazier….(?): make a menu that pops up that can open up the on going streams whenever a favorite Twitch streamer goes live. It’s actually pretty simple, and all I had to do was repurpose an if/else bash script I saw for a shutdown menu, and then make sure I had the proper urls.

The results: a menu that on the press of a hotkey shows me the streamers on Twitch I like to watch. But it doesn’t open them up in the web browser by itself to watch. It opens up the video in the MPV video player with the help of Streamlink, and the chat for now appears in a new firefox window. The script, for now, is simply:

 

#!/bin/bash

chosen=$(echo -e “twitchchannelnamehere” | rofi -dmenu -i)

if [[ $chosen = “twitchchannelnamehere” ]]; then

firefox -new-window https://www.twitch.tv/popout/twitchchannelnamehere/chat?popout= ; streamlink –player mpv twitch.tv/twitchchannelnamehere best

elif ##just used as an example to show how to add more channels

 

fi

A few things about the above script. When it says “twitchchannelnamehere” it’s obviously gonna be where the twitch.tv/ url lands at when you’re on the desired channel’s page. If you want to add more entries to the list, all you need to do is change the list in the second line to include the other names by adding a “\n” in between the channel names. The second line would turn into:

chosen=$(echo -e “TwitchchannelA\nTwitchchannelB” | rofi -dmenu -i)

Also you can change the way the menu looks by changing the -dmenu tag into a different preset.

 

In the “if” and “elif” statemends, the ‘;’ separates multiple bash commands. I found that if the command is something that executes a process that lasts for a while you should place it last in the list of commands to be executed, if you’re using more than one.

 

I decided that this is a fun script to work with, easy to use when it’s bound to a hotkey, and I think it’s not going to be hard even to expand the script to be able to open up a channel that’s typed into a search bar, so the channels that are hard coded could act as a “Favorites” menu, and also maybe make it so it’s easier to add potential favorites to be on the list. In order, the steps to potentially get there would be to look into making a separate rofi config script for the menu so I can add the text entry field, and then write the function to check if the entry is a viable twitch.tv url, and if it is, open the stream in the video player if the person is live- if the person isn’t live perhaps an option to open the page in a browser, and if the url isn’t valid return an ‘invalid url’ option. The function could probably be written in bash, and would likely have to be a separate file than the hard coded scripts, if only for the reason that I am unsure how to make it work in file as time stands now. With video being routed through a player like MPV (VLC could work as well!), recording the videos to your hard drive can be possible, turning your computer into an internet DVR! In the end, though I’m unsure if I’m going to do it. Regardless though there is now more work to be done. So onwards! To see what lies ahead!

In closing this script can even be modified to be used for really anything. The fundamental thing to remember with the bash script is that the “chosen” variable will contain the list to choose from in the menu, and when you write out the commands, all they are are basic bash commands. More rofi menus can be launched, python scripts can be ran, the list is pretty endless.