Page 1 of 1

1 and 1 work but 1+1 doesn't [Solved]

Posted: 25 May 2024, 18:07
by Ed_P
I have 2 scripts, one starts Firefox, one starts wmctrl and the two play well together but when I try to combine them only Firefox starts. :( :%)

Code: Select all

#!/bin/sh
set -x;
firefox https://us0.forgeofempires.com/page/ > /dev/null
sleep 2
wmctrl -r 'Firefox' -e 0,80,0,1865,1100
#sh /home/guest/WMctrl.sh
Changing the sleep time to 5 or 8 didn't help, trying to start the wmctrl script didn't help. :unknown:

1 and 1 work but 1+1 doesn't

Posted: 25 May 2024, 20:36
by donald
This is what I have to start PaleMoon, give the browser some time to settle and
then resize it to a specified location.
May give you some inspiration. :)

Code: Select all

#!/bin/bash

(palemoon &)  & sleep 10 &&
bash -c "wmctrl -r 'Pale Moon' -e 0,80,0,800,600"
palemoon = start the browser and Pale Moon is what the (running) Browser window
is actually named. --- check the window name with:

Code: Select all

wmctrl -l

1 and 1 work but 1+1 doesn't

Posted: 26 May 2024, 01:01
by Ed_P
Thank you donald but bash -c for wmctrl didn't work for me. :(

What I do see from Firefox is:

Code: Select all

ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
Can that be what is stopping wmctrl from executing? Pressing Enter repeatedly does nothing but move the cursor down a line.

Added in 6 minutes 27 seconds:
The Firefox window's name is the name of the site plus " -- Mozilla Firefox" in all cases.

Added in 2 hours 46 minutes 58 seconds:
So, if Firefox is already running and I run my script I get this:

Code: Select all

guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ ./Firefoe.sh
+ firefox https://us0.forgeofempires.com/page/
+ echo 1 done
1 done
+ sleep 5
+ bash -c wmctrl -r Firefox -e 0,80,0,1865,1100
wmctrl 1.07
Usage: wmctrl [OPTION]...
Actions:
  -m                   Show information about the window manager and
                       about the environment.
  :
  :
  :
  :
The "bash -c wmctrl -r Firefox -e 0,80,0,1865,1100" command is missing the script's quotes around Firefox. :crazy:

Added in 42 minutes 47 seconds:
Got it.

Code: Select all

bash -c "wmctrl -r 'Firefox' -e 0,80,0,1865,1100"
works! :good:

But it doesn't run if firefox isn't running and firefox still doesn't start. :wall:

1 and 1 work but 1+1 doesn't

Posted: 26 May 2024, 19:36
by donald
Hm..I'm a bit confused, what exactly does not work?
Added your page to my script

Code: Select all

#!/bin/bash

(palemoon https://us0.forgeofempires.com/page/ &)  & sleep 5 &&
bash -c "wmctrl -r 'Pale Moon' -e 0,80,0,800,600"
and,well, it runs fine.

wmctrl -l shows

Code: Select all

porteus Forge of Empires – A free to play browser game. - Pale Moon
the last part is Pale Moon, if yours is Mozilla Firefox you have to put this into quotes
not only Firefox I think.

EDIT
I took your script ( 1st post ) and modified it so it does work for me.

Code: Select all

#!/bin/sh
set -x;
(palemoon https://us0.forgeofempires.com/page/ > /dev/null &)
sleep 2
bash -c "wmctrl -r Pale Moon -e 0,80,0,800,600"
-- you have to substitute my palemoon browser with your firefox --
and the location values of course.

1 and 1 work but 1+1 doesn't

Posted: 27 May 2024, 03:45
by Ed_P

Code: Select all

#!/bin/sh
set -x;
firefox https://us0.forgeofempires.com/page/   #> /dev/null
echo 1 done
sleep 3 && bash -c "wmctrl -r 'Firefox' -e 0,80,0,1865,1100"
exit

Code: Select all

guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ ./Firefoe.sh
+ firefox https://us0.forgeofempires.com/page/
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.


Firefox starts with the specified website but not wmctrl. :wacko:

Added in 23 minutes 24 seconds:
When I close Firefox I see:

Code: Select all

guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ ./Firefoe.sh
+ firefox https://us0.forgeofempires.com/page/
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
+ echo 1 done
1 done
+ sleep 5
+ bash -c 'wmctrl -r '\''Firefox'\'' -e 0,80,0,1865,1100'
+ exit
guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ 

Added in 12 hours 48 minutes 16 seconds:
Upgraded from firefox-122 to firefox-126, same problem.

What's strange is Firefox starts, even after issuing the Attentions, but the script stops. :hammer:

Added in 2 hours 28 minutes 22 seconds:
This change:

Code: Select all

#!/bin/sh
set -x;
MESA_DEBUG=silent firefox https://us0.forgeofempires.com/page/   #> /dev/null
echo 1 done
sleep 5 && bash -c "wmctrl -r 'Firefox' -e 0,80,0,1865,1100"
exit
yields:

Code: Select all

guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ ./Firefoe.sh
+ MESA_DEBUG=silent
+ firefox https://us0.forgeofempires.com/page/


but doesn't fix wmctrl not starting. :wall: This a bash problem? But it works with your palemoon. :pressure: And when I close Firefox I get the same as before.

Code: Select all

guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ ./Firefoe.sh
+ MESA_DEBUG=silent
+ firefox https://us0.forgeofempires.com/page/
+ echo 1 done
1 done
+ sleep 5
+ bash -c 'wmctrl -r '\''Firefox'\'' -e 0,80,0,1865,1100'
+ exit
guest@porteus:/mnt/nvme0n1p7/porteus5.0/Guest$ 
:crazy:

1 and 1 work but 1+1 doesn't

Posted: 27 May 2024, 22:28
by donald
Ed -- look at my suggested script once more, can you spot the difference to yours?

However, to be on the safe side I installed the newest cinnamon iso + wmctrl-1.07 + firefox-126.
... and it works.

here it is again -- replaced palemoon with firefox -- you only have to use your location/size values.

Code: Select all

#!/bin/sh
set -x;
(firefox https://us0.forgeofempires.com/page/ > /dev/null &)
sleep 6
bash -c "wmctrl -r Mozilla Firefox -e 0,80,0,800,600"

1 and 1 work but 1+1 doesn't

Posted: 27 May 2024, 23:11
by Ed_P
donald wrote:
27 May 2024, 22:28
However, to be on the safe side I installed the newest cinnamon iso + wmctrl-1.07 + firefox-126.
:shock: Wow Thank you :worthy: donald.
donald wrote:
27 May 2024, 22:28
Ed -- look at my suggested script once more, can you spot the difference to yours?
The PARENTHESES make a difference!! :o

Yes, they do.

Code: Select all

guest@porteus:~$ ./Firefoe.sh
+ firefox https://us0.forgeofempires.com/page/
+ sleep 2
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
+ bash -c 'wmctrl -r '\''Firefox'\'' -e 0,80,0,1865,1100'
guest@porteus:~$
:mega_shok: I have NEVER used them around a command in one of my scripts before. EVER.

So my script that now works:

Code: Select all

#!/bin/sh
set -x;
(firefox https://us0.forgeofempires.com/page/ > /dev/null &)
#(MESA_DEBUG=silent firefox https://us0.forgeofempires.com/page/ &)
#MESA_DEBUG=silent firefox https://us0.forgeofempires.com/page/
#bash -c "MESA_DEBUG=silent firefox 'https://us0.forgeofempires.com/page/'"   #> /dev/null
#echo 1 done
sleep 2  
bash -c "wmctrl -r 'Firefox' -e 0,80,0,1865,1100" 
#exit
in a terminal window. But not well with Nemo's Run in Terminal button. It runs and ends and takes Firefox down with it immediately. :hammer: Do I need to add a period or comma somewhere? :D

1 and 1 work but 1+1 doesn't

Posted: 28 May 2024, 00:50
by donald
But not well with Nemo's Run in Terminal button.
Right clicking a script file:
I see only a 'open' option which then gives me a choice between:
Run in Terminal - Display - Cancel - Run
( also if you double click a script )

Click the 'Run' button not the 'Run in Terminal' one.

1 and 1 work but 1+1 doesn't

Posted: 28 May 2024, 04:14
by Ed_P
donald wrote:
28 May 2024, 00:50
( also if you double click a script )

Click the 'Run' button not the 'Run in Terminal' one.
:o That works. :good: But why?? How is Run in Terminal different than running the script when in a Terminal window? :%) I'm thinking of making a desktop file to run the script, will that work?

And Thank You donald for all your help with this. I NEVER would have gotten this far with this on my own.

Added in 13 minutes 39 seconds:
The desktop script now has:

Code: Select all

#Exec=firefox https://us0.forgeofempires.com/page/   
Exec=/home/guest/Firefoe.sh
and it starts Firefox but no wmctrl action. :(

And it WORKS!!!! :Yahoo!: :celebrate3:

:beer: Thank you, thank you :worthy: donald :beer: :beer:


Added in 10 hours 57 minutes 46 seconds:
Final version, which works with my .desktop file.

Code: Select all

#!/bin/sh
# Run in Terminal doesn't work. Use just Run.
# https://forum.porteus.org/viewtopic.php?f=140&t=11323&p=99500#p99500 - donald
(firefox $1  &)
sleep 1  
wmctrl -r 'Mozilla Firefox' -e 0,80,0,1865,1100 

Thank you donald. :friends:

Added in 11 minutes 38 seconds:
1 and 1 work but 1+1 doesn't [Solved]
The .desktop file's exec.

Code: Select all

Exec=/home/guest/Firefox.sh https://us0.forgeofempires.com/page/