Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 19 Sep 2018, 09:01
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Switch to or launch application
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
Uten


Joined: 29 Jan 2008
Posts: 124

PostPosted: Thu 08 Mar 2018, 00:21    Post subject:  Switch to or launch application
Subject description: Bind keys in openbox to this script
 

I have played with openbox (fatdog64-721) tonight.
Turns out there are lots of keybinding options that makes sense.

While playing I came across a question from someone that wanted an application to be brought to the foreground if it was running or launched if it was not. Apparently Ubuntus unity has this. Suggestions and solutions are to be found on net, but they seemed to fail quite often on fatdog. Anyway I ended up with this script which works for me. Also visit the RESOURCE links in the script if you want to know more about keybindings.

OBS: The script requires wmctrl witch you install from gslapt or compile yourself.

Save as xwinfocus.sh somewhere in PATH and chmod +x xwinfocus.sh

Code:
#!/bin/bash
# Set focus to the first window containing the window title string
#      ( and for good measure has a reasonable size )
# If the window is not found we start the application/cmd
#
# REQUIRES: wmctrl (not included in fatdog64-721, install from gslapt)
#
# USAGE: "xwinfocus.sh <window title string> <cmd to start>"
#
#
#
# Another usage is by binding it to a key combination in openbox (or
#      any window/keyboard manager)
# In this case I added these lines to: ~/.config/openbox/rc.xml
#
#    <!-- bind application to W-[0-9] W is the windows key-->
#    <!-- apply changes by: openbox --reconfigure         -->
#    <keybind key="W-1">
#      <action name="Execute">
#        <command>xwinfocus.sh  "Mozilla Firefox" "firefox --private-window"</command>
#      </action>   
#     </keybind>
#    <keybind key="W-2">
#      <action name="Execute">
#        <command>sh -c 'xwinfocus.sh "- Geany" geany'</command>
#      </action>
#    </keybind>
#    <keybind key="W-3">
#      <action name="Execute">
#        <command>sh -c 'xwinfocus.sh Osmo osmo'</command>
#      </action>     
#    </keybind>
#    <keybind key="W-9">
#      <action name="Execute">
#        <command>xwinfocus.sh "mc \[" "urxvt -e mc"</command>
#      </action>     
#    </keybind>   
#    <keybind key="W-0">
#      <action name="Execute">
#        <command>xwinfocus.sh htop "xterm -fg yellow -bg black -title htop -e htop"</command>
#      </action>           
#    </keybind>         
#
# RESOURCE: http://blog.johnnovak.net/2016/11/13/a-minimalist-openbox-desktop-for-vim-freaks/
# RESOURCE: http://melp.nl/2011/01/10-must-have-key-and-mouse-binding-configs-in-openbox/
# RESOURCE:
export app_title="$1"
shift
app_exec="$*"
echo "[$app_title], [$app_exec]"

#wmctrl only lists windows managed (started by) the window manager?
#app_win_id=`wmctrl -lx|grep -i $app|cut -d ' ' -f 1`
# xwininfo has been more reliable on my system (fatdog64)
app_win_id=$(xwininfo -tree -root|awk '$0 ~ /[[:xdigit:]]{3,}x[[:xdigit:]]{3,}/&& ! /(has no name)/ && $0 ~ ENVIRON["app_title"] {$0=$0; print$1; exit}')

if [ -z $app_win_id ]; then
   echo "RUN: $app_exec"
    $app_exec & # app not started, so start it
else
   echo "PROCESS: $app_win_id"
    active_win_id=`wmctrl -r :ACTIVE: -e 0,-1,-1,-1,-1 -v 2>&1|grep U|cut -d ' ' -f 3`
    if [ $app_win_id == $active_win_id ]; then
        wmctrl -r :ACTIVE: -b toggle,hidden    # hide app when active
    else
        wmctrl -i -a $app_win_id    #switch to app
    fi;
fi;
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0256s ][ Queries: 11 (0.0026s) ][ GZIP on ]