0

I've recently been having some trouble with xdotools and bash scripting. I've dipped my toes into make my Linux install look a little bit nicer, and so I decided to have a bash script open up a window upon login to my DE displaying htop. I have managed to automate the process of opening the window, but I am unable to move the windows because I cannot get the proper window ID as the terminal reports this;

./htop.sh: line 5: search: command not found 

Obviously "htop" is the name of the file and "search" is the command I am trying to run to get the window id. Also, to provide some context to this with my code:

#!/bin/bash

# displays 'htop' in the bottom right corner of the screen
xfce4-terminal --hide-borders --hide-toolbar --hide-menubar --title=HTOP --command="bash -c 'clear;htop;$SHELL'" &
WINDOWID=xdotool search --name "HTOP" &
xdotool windowmove $WINDOWID 4526 850 &

Anyways, whenever I run the line,

xdotool search --name "HTOP" # HTOP is the title of the terminal window I open

within my terminal everything works just fine, and as long as the window that the script opens is actually open, it spits out the window ID that I need to further preform the "windowmove" command. So I guess my question is; is this just a bug of xdotool that you cannot preform the functions from withing a bash script? or did I just mess up my syntax somewhere?

smurvy
  • 1
  • 2
  • Note that 6 lines of code is not too much to add it directly to your question by using the appropriate code tags. I've fixed that for you. – mashuptwice Mar 26 '22 at 20:33

1 Answers1

0
WINDOWID=xdotool search --name "HTOP" &

What you are doing here is assigning the string "xdotool" to the variable $WINDOWID.

As the string is followed by a space, your shell interprets everything after the space as a separate command.

If you want to assign the output of a command to a variable you can do that like this:

WINDOWID=&(xdotool search --name "HTOP")

Or by using the deprecated way with backticks:

WINDOWID=`xdotool search --name "HTOP"`

Also note that it makes no sense to run the commands in your script in background (&). Each command relies on the previous to produce a correct result, so what you actually want to do is run them in series, meaning without the trailing &.

mashuptwice
  • 640
  • 3
  • 18