Asking for a small modification of a script for the tent-mode for a convertible

@humpty

Sorry to ask, but … at the moment I use this content in one-button-toggle.sh:

#!/bin/sh
if [ -f ~/flag_is.inverted ]; then 
   xrandr -o normal
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
   rm ~/flag_is.inverted
else
   xrandr -o inverted
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
   touch ~/flag_is.inverted
fi

It’s so cool, because now I can use only one shortcut and I can use only one symbol-script in the panel for switching.

But there are two disadvantages:

  • flag_is.inverted is created in the home-file
  • I can’t put the script in the /usr/local/bin, because of the created flag_is.inverted.

Is there a possibility to change the following line?

if [ -f ~/flag_is.inverted ]; then

in something like

if [ -f; xrand -o =="inverted" ]; then

, so that no flag_is.inverted is created?

I have no idea how to program it because I don’t know the program language. Maybe this script could help to find a solution:

Thank you very much for an answer in advance.

I put the original script in /usr/local/bin and didn’t have any problem with it. It was still able to find ~/flag_is.inverted. Just make sure the script is owned by you (not root) and is executable.

If you don’t like the file-flag, you can try this instead,


#!/bin/bash

BEFORE=`xrandr | grep " connected" | cut -d" " -f5`

#if [ -f ~/flag_is.inverted ]; then
if [ "$BEFORE" == "inverted" ]; then
   xrandr -o normal
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
#   rm ~/flag_is.inverted
else
   xrandr -o inverted
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
#   touch ~/flag_is.inverted
fi

Note: there’s a space before " connected".

(If you have any non-Lubuntu questions, e.g scripting, you can message me directly, or post in Offtopic section).

I copied and pasted the code, but the script does not flip back.

!/bin/bash

BEFORE=`xrandr | grep " connected" | cut -d" " -f5`

if [ "$BEFORE" == "inverted" ]; then
   xrandr -o normal
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
else
   xrandr -o inverted
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
fi

The only thing what I changed was the script name from
one-button-toggle.sh
to
toggle_tent-mode.sh.

What is your output for
xrandr
?

normal mode:
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 256mm x 144mm
when it is inverted:
eDP-1 connected primary 1920x1080+0+0 inverted (normal left inverted right x axis y axis) 256mm x 144mm

Do you need the whole content?
The rest of the lines are equal. I just compared both documents with Meld.

Looks fine to me.

Run this;

#!/bin/bash

xrandr -o inverted
BEFORE=`xrandr | grep " connected" | cut -d" " -f5`
echo $BEFORE

xrandr -o normal
BEFORE=`xrandr | grep " connected" | cut -d" " -f5`
echo $BEFORE

You should see
inverted
(normal

That is what I see:
inverted
(normal

normal mode:
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 256mm x 144mm

when it is inverted:
eDP-1 connected primary 1920x1080+0+0 inverted (normal left inverted right x axis y axis) 256mm x 144mm

And then, if I press again the shortcut to flip back, then the line from above does not change:
eDP-1 connected primary 1920x1080+0+0 inverted (normal left inverted right x axis y axis) 256mm x 144mm

I just compared the documents with Meld.

Are you sure you are using #!/bin/bash ?
Don’t use #!/bin/sh
The two are not the same.

Alternatively, just replace
"$BEFORE" == "inverted"
with
"$BEFORE" = "inverted"

I will try your last comment in the next hours. But maybe the problem is there: In shortcuts I have as command this:
sh toggle_tent-mode.sh
Is that correct?

No. That will run the script as a bourne shell script (sh).
sh does not like == as a comparator. So use = instead (bash doesn’t mind either).

You don’t need anything before toggle_tent-mode.sh. You just have to make sure that it’s executable and owned by you.

sudo chown username:username toggle_tent-mode.sh
chmod +x toggle_tent-mode.sh

Just remove ‘sh’ from the shortcut, or if you must invoke, choose ‘bash’ instead.

That was the solution:
"$BEFORE" = "inverted"

Now it works fine, even with sh toggle_tent-mode.sh.
Tomorrow I will make a profound test. I will note here the result.

@humpty Thank you so much for your help.

That is the complete solution of the last three topics:
A SHORTCUTS

normal (Shift+F1):
bash -c ‘xrandr -o normal && xinput set-prop ‘FTSC1000:00 2808:5012’ ‘Coordinate Transformation Matrix’ 1 0 0 0 1 0 0 0 1’

inverted (Shift+F2):
toggle_inverted.sh

left (Shift+F3):
bash -c ‘xrandr -o left && xinput set-prop ‘FTSC1000:00 2808:5012’ ‘Coordinate Transformation Matrix’ 0 -1 1 1 0 0 0 0 1’

right (Shift+F4):
bash -c ‘xrandr -o right && xinput set-prop ‘FTSC1000:00 2808:5012’ ‘Coordinate Transformation Matrix’ 0 1 0 -1 0 1 0 0 1’

B SCRIPT
toggle_inverted.sh:

#!/bin/bash

BEFORE=`xrandr | grep " connected" | cut -d" " -f5`

if [ "$BEFORE" = "inverted" ]; then
   xrandr -o normal
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
else
   xrandr -o inverted
   xinput set-prop 'FTSC1000:00 2808:5012' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
fi

Then I did this in the terminal:
sudo mv toggle_inverted.sh /usr/local/bin
and
sudo chmod +x /usr/local/bin/toggle_inverted.sh

C PANEL
I dragged toggle_inverted.sh from /usr/local/bin in the panel, in the quick launch.

@humpty
It is so perfect now. Thank you so much for your help.

Thank you so much for that, because I don’t know how to program scripts, and maybe one day I will need just a small help. For the last years I’m using two scripts for Lubuntu in general that I like and that I found somewhere in the internet:

update.sh (I use it in the terminal):
#!/bin/bash
apt update
apt dist-upgrade -y
poweroff.sh (I use it with a shortcut):
#!/bin/bash
zenity --question --text="poweroff?"
if [ $? = 0 ]; then
	systemctl poweroff
else
	exit
fi
1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.