You are not logged in.

#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: 5,592

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>'

Offline

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

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

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.

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: 65
Website

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

#26 2016-09-06 01:30:23

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

Re: Openbox: List my Steam games for me!

Davy wrote:

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?

https://developer.valvesoftware.com/wik … Windows.29
It would seem not.

@Eraph I'll check that out, I'm really glad we got some input on using different methods to increase the speed for this kind of script.


Public Key | My Tongue
Bitcoin: 1EPjsUvbr8vR5DiWQFYNwiyGML63iZUWWc

Offline

Board footer

Powered by FluxBB