You are not logged in.

#1 2016-02-01 14:05:14

Viomi
Member
Registered: 2016-01-29
Posts: 10

Openbox: List my Steam games for me!

This is a bash script for Openbox that lists all of your installed steam games in your little openbox window thing.

CJx6EeN.png

#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.

#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>

#!/bin/bash

STEAMAPPS=~/.local/share/Steam/steamapps

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $(ls $STEAMAPPS/*.acf -1v); do
    ID=$(cat "$file" | grep '"appid"' | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')
    NAME=$(cat "$file" | grep '"name"' | head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

Pretty straightforward if I do say so myself.


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#2 2016-02-01 16:39:33

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: Openbox: List my Steam games for me!

Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#3 2016-02-01 16:55:51

damo
....moderator....
Registered: 2015-08-20
Posts: 6,266

Re: Openbox: List my Steam games for me!

Horizon_Brave wrote:

Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.

...and from the archives: The ultimate pipe menu thread


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#4 2016-02-01 17:48:23

Viomi
Member
Registered: 2016-01-29
Posts: 10

Re: Openbox: List my Steam games for me!

damo wrote:
Horizon_Brave wrote:

Hey, that's neat! I need to work on and practice using the pipe menus for openbox. Seem's like there's a lot of neat things you can do with 'em.

...and from the archives: The ultimate pipe menu thread

Heh, I had originally had help from someone back on the #! forums with creating this script in the first place. (In fact, I think they made the original, and then I recreated it because it was broke ;3; )

Last edited by Viomi (2016-02-01 17:48:34)


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#5 2016-02-01 20:16:38

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

try this instead:

#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.

#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>

#!/bin/bash

STEAMAPPS=~/.local/share/Steam/steamapps

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.acf ; do
    ID=$(grep '"appid"' "$file" | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')
    NAME=$(grep '"name"' "$file"| head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

i guess one could shorten/improve it more, but i don't know what these .acf files contain...


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#6 2016-02-02 14:53:30

Viomi
Member
Registered: 2016-01-29
Posts: 10

Re: Openbox: List my Steam games for me!

ohnonot wrote:

try this instead:

#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.

#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>

#!/bin/bash

STEAMAPPS=~/.local/share/Steam/steamapps

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.acf ; do
    ID=$(grep '"appid"' "$file" | head -1 | sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')
    NAME=$(grep '"name"' "$file"| head -1 | sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

i guess one could shorten/improve it more, but i don't know what these .acf files contain...

I believe it's just a json list with different values, including appid and name.


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#7 2016-02-04 03:35:01

Viomi
Member
Registered: 2016-01-29
Posts: 10

Re: Openbox: List my Steam games for me!

Bump because I updated the script per recommendation of @ohnonot
I've also made it use awk instead of sed.

#This script is a generally used Openbox pipe menu to list all currently installed steam games as well as launch them.

#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>

#!/bin/bash

STEAMAPPS=~/.local/share/Steam/steamapps

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $(ls $STEAMAPPS/*.acf -1v); do
   ID=$(grep '"appid"' "$file" | head -1 | awk -F\" '{print $4}')
   NAME=$(grep '"name"' "$file" | head -1 | awk -F\" '{print $4}')
   echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>steam -applaunch $ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#8 2016-02-04 07:41:46

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

Viomi wrote:
for file in $(ls $STEAMAPPS/*.acf -1v); do

why do you insist on parsing ls, which the old guys with the long beards consider a really bad idea?
if you really must, it should be /usr/bin/ls or $(which ls), but why, if a simple * does the same (in this case).
to prove my point, i rewrote the script for .desktop files, just to be able to test it:

#!/bin/bash

STEAMAPPS="/usr/share/applications"

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.desktop ; do
    ID="$(cut -d= -f2 <<<$(grep -i 'Exec' "$file"))"
    NAME="$(cut -d= -f2 <<<$(grep -i 'Name' "$file"))"
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>$ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

(i also prefer to use the '<<<' construct instead of pipes '|', whenever possible.)


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#9 2016-02-04 18:02:06

Viomi
Member
Registered: 2016-01-29
Posts: 10

Re: Openbox: List my Steam games for me!

I don't "insist" on parsing ls. I didn't know old men with beards think it's a bad idea.

I also don't understand what's wrong with pipes. Would you like to be informational and educate me about it, and tell me why it's wrong?


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#10 2016-02-04 18:29:48

damo
....moderator....
Registered: 2015-08-20
Posts: 6,266

Re: Openbox: List my Steam games for me!

Why you shouldn't parse the output of ls

From the ultimate bash guru who wrote that:

All in all, you really can't and shouldn't trust the output of ls to be a true representation of the filenames that you want to work with. So don't.

Also if you can avoid pipes, and/or do parameter substitution, it is a lot more efficient - less processes started and stopped etc.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#11 2016-02-05 03:46:23

Viomi
Member
Registered: 2016-01-29
Posts: 10

Re: Openbox: List my Steam games for me!

Your $ID and $NAME lines error, but the rest is great. Thanks.


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

#12 2016-02-05 07:55:58

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

Viomi wrote:

I also don't understand what's wrong with pipes. Would you like to be informational and educate me about it, and tell me why it's wrong?

hey, it's ok, just trying to improve things. it's FOSS after all, right?
pipes are great and useful.
it's not apparent to the casual user, but every pipe opens a new shell (i hope i'm phrasing this right).
with the '<<<' construct (i don't even know what that's called) i can do almost the same as with a pipe, but stay within the same shell.
for every script i write i try to optimize it as much as i can. with my changes, you are executing far less processes (no awk, no ls, no pipes) than with your version. pipemenus are executed everytime you hover over them in the menu, so every performance gain matters. at least to me.

Viomi wrote:

Your $ID and $NAME lines error, but the rest is great. Thanks.

where? how? not on my system.
show us!
(it is possible that it doesn't work as an actual openbox pipemenu, i just whipped it up to prove my point even without using steam)


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#13 2016-02-05 08:04:42

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Openbox: List my Steam games for me!

ohnonot wrote:

with the '<<<' construct (i don't even know what that's called)

It's called a here document wink

See http://www.tldp.org/LDP/abs/html/here-docs.html

EDIT: No, it's not, I'm getting confused. I don't know what it's called either  ops

Just ignore me...

Last edited by Head_on_a_Stick (2016-02-05 08:07:06)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#14 2016-02-05 08:18:18

damo
....moderator....
Registered: 2015-08-20
Posts: 6,266

Re: Openbox: List my Steam games for me!

http://www.tldp.org/LDP/abs/html/x17837.html

"A here string can be considered as a stripped-down form of a here document.
It consists of nothing more than COMMAND <<< $WORD,
where $WORD is expanded and fed to the stdin of COMMAND"


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#15 2016-02-05 19:01:17

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Openbox: List my Steam games for me!

Thanks damo!

I knew it was here something...
lol


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#16 2016-02-05 20:15:01

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Openbox: List my Steam games for me!

There is one drawback to using here-docs or here-strings: bash is using a temp file to store the content of whatever follows << or <<<.
You can see it when you run strace on that script, like so:

me@medion:~/tmp/today/quicktests$ strace -o strace -f -tT ./t1

I have dropped the script in a directory quicktest as file t1.
The strace command (install package strace if the command is not there) output goes to file 'strace' in the current directory.

You can see the temp files when you search file strace for 'tmp/'.
Search the file for 'execve' to see what external commands it uses.

Don't know if using here-docs or here-strings should be preferred over using pipes. Could depend on what you are actually doing. Perhaps its worth benchmarking the two solutions per specific case?

For small scripts that take seconds to run, it doesn't make any difference.

Offline

#17 2016-02-06 12:25:42

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

thanks for the extra info!

xaos52 wrote:

For small scripts that take seconds to run, it doesn't make any difference.

imho, it does make a difference for ob pipemenus, because the actual script gets executed everytime you even hover your mouse over the menu entry.

but hey, i don't want to sound nitpicking for the OP, i'm just trying to improve things.

if one could actually see those steam files, it could probably be improved even more.

i am myself regularly blown by what one can do with bash - mere mortals have to write 10 lines of code with ifs and pipes, but if you have the know-how, you do it in one short command with lots of weird-looking characters....


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#18 2016-02-06 13:25:28

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Openbox: List my Steam games for me!

imho, it does make a difference for ob pipemenus, because the actual script gets executed everytime you even hover your mouse over the menu entry.

Offline

#19 2016-02-06 13:30:07

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Openbox: List my Steam games for me!

I agree that speed is essential here.
I wonder if a benchmark could be usefull?
My gut feeling is that using here-documents or here-strings (I/O operation involved) in this case could lose it from creating extra processes(processing + memory involved). It would still depend on your system being I/O-bound or memory-bound.

Offline

#20 2016-02-07 08:07:06

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

i'm sorry i didn't understand that.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#21 2016-02-07 09:53:08

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Openbox: List my Steam games for me!

What I meant is:

Using the << or <<< operations in a bash script could make it slower than using pipes.

Because the  first option uses a file operation ( it copies to a tmp file )and the latter does not.

Offline

#22 2016-02-07 11:01:27

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

hmm.
first of all, for any versions it's best to use "grep -m1" which means that grep will only return the first result (same as | head -1).
with that improvement in place:

'<<<' construct (here-doc?):

$ time testscript
real	0m3.476s
user	0m1.190s
sys	0m0.143s

'|' aka pipes:

$ time testscript
real	0m2.580s
user	0m1.207s
sys	0m0.133s

testscript:

#!/bin/bash

STEAMAPPS="/usr/share/applications"

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.desktop ; do
    #~ ID="$(cut -d= -f2 <<<$(grep -im1 'Exec' "$file"))"
    ID="$(grep -im1 'Exec' "$file"|cut -d= -f2 -)"
    #~ NAME="$(cut -d= -f2 <<<$(grep -im1 'Name' "$file"))"
    NAME="$(grep -im1 'Name' "$file"|cut -d= -f2 -))"
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>$ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#23 2016-02-07 11:10:37

ohnonot
...again
Registered: 2015-09-29
Posts: 4,877
Website

Re: Openbox: List my Steam games for me!

Correction!
It's even faster with dash (but that requires the piped version i think).

Viomi, would you please try this:

#!/bin/dash

STEAMAPPS="$HOME/.local/share/Steam/steamapps"

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.acf ; do
    ID="$(grep -im1 '"appid"' "$file"|sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')"
    NAME="$(grep -im1 '"name"' "$file"|sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')"
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>$ID</execute></action></item>"
done
echo '</openbox_pipe_menu>'

i still don't know what those .acf files look like, so i don't know what that sed command actually does.
or if steam stores a list of installed apps anyway.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#24 2016-05-31 08:06:26

Eraph
Member
From: /au/qld/bne
Registered: 2016-02-29
Posts: 282
Website

Re: Openbox: List my Steam games for me!

So I just manually added entries for a few games to my OpenBox menu, and then found this script to do it for me. Great stuff! Tell you what though, any chance it could be ordered alphabetically? It seems that this would be easy enough using ls but that's already been discouraged.

-- Edit
After a bit more raking around, I found this article which had an example that worked. Turns out, putting the | sort after the done works (?!)
Just when I think I'm starting to get my head around scripting... lol

Here's how mine looks, WARNING: my SteamApps default install directory is different to the original poster's.

#This script creates an Openbox pipe menu to list all currently installed steam games as well as launch them.

#To install:
#Put this script in ~./config/openbox/scripts/steam.sh (or elsewhere if you want to edit the below <menu>)
#Edit the preferences of steam.sh to allow running as a program
#Add the below line to menu.xml (without the comment of course)
#<menu execute="~/.config/openbox/scripts/steam.sh" id="steam" label="Steam"/>

#!/bin/bash

STEAMAPPS="$HOME/.steam/steam/steamapps"

echo '<openbox_pipe_menu>'
echo '<item label="Launch Steam"><action name="Execute"><execute>steam</execute></action></item>'
echo '<separator/>'
for file in $STEAMAPPS/*.acf ; do
    ID="$(grep -im1 '"appid"' "$file"|sed -r 's/[^"]*"appid"[^"]*"([^"]*)"/\1/')"
    NAME="$(grep -im1 '"name"' "$file"|sed -r 's/[^"]*"name"[^"]*"([^"]*)"/\1/')"
    echo "<item label=\"$NAME\"><action name=\"Execute\"><execute>$ID</execute></action></item>"
done | sort
echo '</openbox_pipe_menu>'

Last edited by Eraph (2016-05-31 08:45:03)


Lenovo IdeaPad Yoga 13 | BunsenLabs Hydrogen (x64)
Intel Core i7-3537U | Intel HD4000 | 8GB DDR3 | 256GB SSD

Offline

#25 2016-06-03 13:58:21

Davy
Member
From: Ireland
Registered: 2016-05-31
Posts: 59

Re: Openbox: List my Steam games for me!

This is great!
If I wanted to add an item to open up the friends window, how would I do that? Is there a command to open the friends window?

Last edited by Davy (2016-06-03 13:58:39)

Offline

Board footer

Powered by FluxBB