2

I am trying to get the Aero Snap effect working on an Ubuntu 14.10 using Gnome Classic Metacity.

I found a command that works if I execute in on a terminal window:

wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk '{ print (($2/2))}'`,`xwininfo -root | grep Height | awk '{ print $2 }'`

And I can run it with a sleep 1 to have time to switch to the window I want to resize:

sleep 1 && wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk '{ print (($2/2))}'`,`xwininfo -root | grep Height | awk '{ print $2 }'`

It works well.

I can also run it as a bash script in my $HOME/bin/left.sh and $HOME/bin/right.sh, or shorter, Alt+F2 then $HOME/bin/aaa for left and $HOME/bin/fff for right. It also works on the active window behind the Alt+F2 menu.

Now I want to hook up this command to a keyboard shortcut. I tried:

System Settings -> Keyboard -> Shortcuts -> Custom Shortcuts -> "Aero Left" - Super+Left

which I link to a /bin/bash /home/myusername/bin/aero_left.sh with the command line above. But it has no effect. Again, running the bash command in a terminal window does work, but the keyboard shortcut does not.

In fact, not much happens for any of the Custom Shortcuts I try to set up:

/usr/bin/mplayer /usr/share/aisleriot/sounds/splat.ogg

or

/bin/bash -c "/usr/bin/mplayer /usr/share/aisleriot/sounds/splat.ogg"

and try to hook it to any kind of keyboard combination, it doesn't work...

UPDATE: I tried xbindkeys and none of my examples are working. Still mesmerized as to why the Custom Shortcuts do not do much. Looking forward to a solution.

[hpenvy15 ~] $ mkdir ~/bin ; ls -l -d1 ~/bin | wc -l
1
[hpenvy15 ~] $ cat > ~/bin/left.sh
#!/bin/bash
sleep 0.1 && wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk '{ print (($2/2))}'`,`xwininfo -root | grep Height | awk '{ print $2 }'`
^C
[hpenvy15 ~] $ cat > ~/bin/right.sh
#!/bin/bash
sleep 0.1 && wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,`xwininfo -root | grep Width | awk '{ print (($2/2)+5) ",0," (($2/2)) }'`,`xwininfo -root | grep Height | awk '{ print $2 }'`
^C

[hpenvy15 ~] $ sudo apt-get install xbindkeys
Reading package lists... Done
Building dependency tree       
Reading state information... Done
xbindkeys is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

printf '"bash $HOME/bin/left.sh"\n Mod4+Super_L+Left\n' > ~/.xbindkeysrc
printf '"bash $HOME/bin/right.sh"\n Mod4+Super_L+Right\n' >> ~/.xbindkeysrc
xbindkeys

If I then type control+alt+b I can hear a drum sound, but nothing happens.

Any ideas?

AEM
  • 1,154
719016
  • 6,487
  • As you execute the command in terminal, here the active window is terminal. So, it takes effect only on terminal. – Wolverine Dec 31 '14 at 12:35
  • with the sleep 1, I can change to another window, like a Chrome browser, and then the command takes effect there. I can also do Alt+F2 and execute the bash file, and it works. What does not work is the keybinding. – 719016 Jan 03 '15 at 08:51
  • Yep. You are right!!! The time interval is the key factor of making effect of the command on other windows. But you have to make it with shortcut key as you said earlier that you wanted to do it by shortcut key. I have tried of using native keyboard shortcut options on System Settings. It doesn't work. That's why I preferred over Keybinding application. – Wolverine Jan 03 '15 at 11:17
  • I tried with control+alt+b with xbindkeys but it does not work for me. – 719016 Jan 03 '15 at 11:54
  • What is your script file name? – Wolverine Jan 03 '15 at 11:58
  • $HOME/bin/aaa for what I would like to be Super+left and $HOME/bin/fff for what I would like to be Super+right. – 719016 Jan 03 '15 at 12:35
  • Script file ends with .sh extension. But your's wasn't so. – Wolverine Jan 03 '15 at 12:40
  • More details in the body of the question. – 719016 Jan 03 '15 at 12:48
  • Do you really have bin directory in Home folder? Your answer will be ready in few minutes. – Wolverine Jan 03 '15 at 12:59
  • More comments added – 719016 Jan 03 '15 at 13:02
  • Okay. I'm working on it. – Wolverine Jan 03 '15 at 13:08
  • Type printf '"bash $HOME/bin/left.sh"\n Control+Alt+B' > ~/.xbindkeysrc. Then, type xbindkeys to start xbindkeys in background. If you ever changed existing shortcut key in the xbindkeysrc file, you will have to kill the xbindkeys, application running in background, by typing killall xbindkeys and restart it by typing xbindkeys. – Wolverine Jan 03 '15 at 13:17
  • That's great. Finally it's worked. Right? – Wolverine Jan 03 '15 at 15:10
  • It did! :-) Very happy with this, since now it's fast as hell to do. Next step is to do the same with 2 screens: http://askubuntu.com/q/568716/17702 – 719016 Jan 04 '15 at 12:16

1 Answers1

0

Here the steps:

  1. Create a script file that starts the line #!/bin/bash followed by your command given in the question.
  2. sudo apt-get install xbindkeys
  3. Type:

    printf '"bash $HOME/bin/left.sh"\n Control+Alt+A\n' > ~/.xbindkeysrc 
    printf '"bash $HOME/bin/right.sh"\n Control+Alt+F\n' >> ~/.xbindkeysrc
    
    xbindkeys
    

Now, check out if it does work.

I hope it will work.

Wolverine
  • 664
  • No luck... I tried different shortcut combinations, but none of them works. – 719016 Dec 31 '14 at 13:17
  • I tried it. It works well for me. But I didn't try with Super + Left. I tried with other shortcut keys. It works well. First, check out with other shortcut keys like the one I mentioned in the answer. – Wolverine Dec 31 '14 at 13:41