2

I'm not experienced in scripting but I've made this script:

#!/usr/bin/env bash

# hint: use "xdotool getmouselocation" to get values

if xdotool getwindowfocus getwindowname | grep -Eq " - LibreOffice Calc$"
  then 
    xdotool mousemove --sync 218 144 click 1
fi 

The purpose is to have a keyboard shortcut to using the sum function in LibreOffice Calc 4.4.5. There is no default keyboard shortcut in LibreOffice Calc and it doesn't seem possible to assign one to the sum function: see Bug 39302.

The shortcut executes mousemove only when a Calc window is in focus. Otherwise, it should do nothing. (The coordinates are specific to my usage.)

My question is this: is there a better way to check whether the Calc window is in focus?

How do I change key bindings based on which window is focused? seems related but doesn't have an answer.

  • Did you try this -gist.github.com/kui/2622504 .. it looks like a simple c routine to get active window. I have neither used nor tested it btw ... – amisax Aug 17 '15 at 4:37
  • If you're unsure about the results of if and pipe, run the subcommands alone first, then chain them. That is xdotool .... Then xdotool ... | grep ... ; echo $?. Then if ... then. You also can run the script with sh -x script. – ott-- Aug 17 '15 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.