xdotool's type command eating characters

5,709

Solution 1

The --sync option was exactly what I was looking for!

However, the --sync option only exists on a particular set of get or search commands.

The solution turned out to be: xdotool getwindowfocus windowfocus --sync type [email protected]

What's happening here is that we first get the window that is focused, via getwindowfocus (getactivewindow is an alternative if the other doesn't work).

All we're doing differently is getting the active window and setting it to the same thing. The key difference is the presence of the --sync option which forces xdotool to wait until the previous command has been applied.

So we guarantee that we're focused to a particular window and will be able to type commands.

Solution 2

You may need to increase the delay between keystrokes using --delay (default is 12ms):

xdotool type --delay 100 [email protected]
Share:
5,709

Related videos on Youtube

wafflecat
Author by

wafflecat

Updated on September 18, 2022

Comments

  • wafflecat
    wafflecat over 1 year

    I'm trying to get xmonad to type a common sequence of characters whenever I hit a simple key combo. One instance of this problem is simply typing my email address.

    This is what the configuration file for xmonad looks like for me:

    import XMonad
    import XMonad.Config.Gnome (gnomeConfig)
    import XMonad.Util.CustomKeys (customKeys)
    import XMonad.Util.EZConfig
    
    main = xmonad $ gnomeConfig {
      keys = customKeys delKeys insKeys,
      logHook = return ()
      }
      where
        -- Remap mod-p to dmenu and mod-[sd] to swapping xinerama screens.
        delKeys :: XConfig l -> [(KeyMask, KeySym)]
        delKeys XConfig { modMask = modMask } =
          [ (modMask, xK_p), (modMask, xK_w), (modMask, xK_e) ]
    
        insertEmailAddress :: KeyMask -> [((KeyMask, KeySym), X())]
        insertEmailAddress modMask = [ ((noModMask, xK_Menu), spawn "xdotool type [email protected]") ]
    
        insKeys :: XConfig l -> [((KeyMask, KeySym), X())]
        insKeys XConfig { modMask = modMask } = insertEmailAddress modMask
    

    However, when I hit my menu key (it's in the bottom right of my keyboard) I get only the last half or so. Like: [email protected] or [email protected]. It's totally unpredictable where the printing will start.

    I have found a workaround by changing the xdotool command to xdotool sleep 0.1 type [email protected]. This seems to work without fail but I have no idea why. Any thoughts?

    using xmonad 0.11 & xdotool version 3.20140217.1