2

What we have here is a code that looks for the title

AAA

if it finds it, it activates it and then repositions it.

but the problem is, if the file is not open.. it will
open it just fine. however won't activate and reposition it.

a=`xdotool search --name "AAA"`
if [[ "$a" ]]; then
   xdotool windowactivate --sync $a
   xdotool windowmove --sync $a 377 153
  else
   leafpad '/media/1/AAA'
   xdotool windowactivate --sync $a
   xdotool windowmove --sync $a 377 153
  fi

UPDATE

i suppose it doesn't have to activate it, given that it would be active when opened, but it can not reposition it.

Torxed
  • 22,866
  • 14
  • 82
  • 131
  • the question has been updated with data. –  Aug 18 '13 at 21:19
  • welcome to SO, you don't need to comment on your question that you've updated with data (we can see it, and we get notifications about it.. mostly). Could you please describe what your actual problem is (and please don't tag Python unless it's python related.. won't solve your issue any faster). – Torxed Aug 18 '13 at 21:21
  • So, if you open a windows with the title `AAA` it doesn't get re-positioned? Is that the issue? – Torxed Aug 18 '13 at 21:23
  • @Torxed, i got used to commenting about such things when i noticed they comment when they want to mark a question as 'off topic' so trolling seems to be a 'generic' thing around here. –  Aug 18 '13 at 21:24
  • @Torxed, yes i think xdotool does not take the time to check if the window is active after it opens the file. whiel in the first one it can because the window is already open. i tried adding some random code so i could cause a 2 second delay, but it did not work, i believe.. `xdotool key F6 --delay 2000` was the line i tried. –  Aug 18 '13 at 21:25
  • Check my answer, the `sleep` might help but shouldn't be needed. The real problem was that you didn't redefine `$a` after starting leafpad. – Torxed Aug 18 '13 at 21:27

1 Answers1

2

Not quite sure what the user is having issues with but here we go:

a=`xdotool search --name "AAA"`
if [[ "$a" ]]; then
   xdotool windowactivate --sync $a
   xdotool windowmove --sync $a 377 153
else
   leafpad '/media/1/AAA'
   sleep 5
   a=`xdotool search --name "AAA"`    # <-- You need this
   xdotool windowactivate --sync $a   # <-- Otherwise $a will be empty (think about it)
   xdotool windowmove --sync $a 377 153
fi

The reason for the window not being re-positioned is because:

You search for 'leafpad' and place it in $a, but if leafpad isn't started $a will be empty when you go into the else block. So you need to search and place leafpad in $a after it's launched again in order to move it.

Torxed
  • 22,866
  • 14
  • 82
  • 131
  • $a was defined on top, i defined it again anyway as you recommended but it does not solve the problem. as far as sleep 5 goess.. i am not certain why that portion is not working. –  Aug 18 '13 at 21:41
  • although this question does not solve the problem, i will choose it anyway so i can gain 2 points. –  Aug 18 '13 at 21:42
  • `$a` was defined at the top, but it will be empty because there was no window with "AAA" (that's why you're starting leafpad...). So once there IS a window with "AAA", you need to put THAT window into `$a`. – Torxed Aug 18 '13 at 21:43
  • 1
    o i see, i rethought about it and realized it's logical what you said so i fixed it up a bit and tried again, now it is working, –  Aug 18 '13 at 21:51