Logitech and Solaar

I got a nice discount on an MK345 (decent keyboard, junk mouse - and no unifying support) keyboard. Improvement on my old K270 as the letters had worn off (and I need them for Thai input…).

The issue I’m having is that instead of dedicated keys, the ‘function’ keys are all on the Fkeys with a Fn shortcut. No dedicated media keys…

So I figured out I can install Solaar-git, open it up, and use the Swap Fx Function. This works well with my K400 for when I’m listening to music etc… but not with a main keyboard where I sometimes need to push F buttons - and the Fn key is too far to do it with one hand.

So I want to switch them…

The keyboard lists (command ‘solaar show’) as device 1.

If I type ‘solaar config 1 | grep fn-swap’ I get some errors and an output:

Summary

(solaar:1857191): Gtk-WARNING **: 14:18:03.647: Theme parsing error: gtk.css:68:35: The style property GtkButton:child-displacement-x is deprecated and shouldn’t be used anymore. It will be removed in a future version

(solaar:1857191): Gtk-WARNING **: 14:18:03.647: Theme parsing error: gtk.css:69:35: The style property GtkButton:child-displacement-y is deprecated and shouldn’t be used anymore. It will be removed in a future version

(solaar:1857191): Gtk-WARNING **: 14:18:03.647: Theme parsing error: gtk.css:73:46: The style property GtkScrolledWindow:scrollbars-within-bevel is deprecated and shouldn’t be used anymore. It will be removed in a future version
Gtk-Message: 14:18:03.665: Failed to load module “appmenu-gtk-module”
fn-swap = False

fn-swap is false.

Next we can do 'solaar config 1 fn-swap= “True”
also we can do 'solaar config 1 fn-swap=“False”

But what I want to do is to have a little script.

  1. check fn-swap
  2. if false, then set true
  3. if true, then set false

This I can then launch with a simple shortcut/mouse gesture.

How can I do this?

I have script ‘fn-swap.sh’

#!/bin/bash
if solaar config 1 | grep fn-swap “True”
then solaar config 1 fn-swap= “False”
else solaar config 1 fn-swap= “True”
fi

But I get this:

Summary

solaar: error: Traceback (most recent call last):
File “/usr/lib/python3.8/site-packages/solaar/cli/init.py”, line 199, in run
m.run(c, args, _find_receiver, _find_device)
File “/usr/lib/python3.8/site-packages/solaar/cli/config.py”, line 74, in run
raise Exception(“no setting ‘%s’ for %s” % (args.setting, dev.name))

Exception: no setting ‘fn-swap=’ for Wireless Keyboard MK270

Hmmmmm…

I’m confused because:

but

MK345 is a wireless keyboard/mouse combination.
You get an MK270 keyboard, a M275 mouse, and both are fixed/paired to a standard Logi Nano dongle. Sadly they won’t pair to my unifying dongles (I have 2, which can pair 6 devices each… but are only useful for my K400 now).

I made a new script, first option I guess is to work out what’s working:

Summary

#!/bin/bash

commands () {

solaar config 1 fn-swap “true”

solaar config 1 | grep fn-swap

sleep 10

solaar config 1 fn-swap “false”

solaar config 1 | grep fn-swap

$SHELL # keep the terminal open after the previous commands are executed

}

export -f commands

konsole -e “bash -c ‘commands’”

Now I get a terminal window that says it’s setting it to true, then verifies it’s true.
The same works with ‘false’ but I want ONE script to swap them.

First script:

leads to Exception: no setting ‘fn-swap=’

Second script:

Seems the right way to pass the value.

1 Like

#!/bin/bash
solaar config 1 fn-swap “true”

I now have two mapped, one true, the other false. This works. Is there any way to extend this to ‘toggle’ instead?

What about:

#!/bin/bash
if solaar config 1 | grep fn-swap "true"
then solaar config 1 fn-swap "false"
else solaar config 1 fn-swap "true"
fi

Looks good, doesn’t work.

Summary

Traceback (most recent call last):
File “/usr/lib/python3.8/site-packages/solaar/cli/init.py”, line 199, in run
m.run(c, args, _find_receiver, _find_device)
File “/usr/lib/python3.8/site-packages/solaar/cli/config.py”, line 92, in run
raise Exception("%s: don’t know how to interpret ‘%s’ as boolean" % (setting.name, value))
Exception: fn-swap: don’t know how to interpret ‘“true”’ as boolean

I used a capital there, because the output gives False, not false…

Summary

❯ solaar config 1 | grep fn-swap

(solaar:1897102): Gtk-WARNING **: 15:39:17.295: Theme parsing error: gtk.css:68:35: The style property GtkButton:child-displacement-x is deprecated and shouldn’t be used anymore. It will be removed in a future version

(solaar:1897102): Gtk-WARNING **: 15:39:17.295: Theme parsing error: gtk.css:69:35: The style property GtkButton:child-displacement-y is deprecated and shouldn’t be used anymore. It will be removed in a future version

(solaar:1897102): Gtk-WARNING **: 15:39:17.295: Theme parsing error: gtk.css:73:46: The style property GtkScrolledWindow:scrollbars-within-bevel is deprecated and shouldn’t be used anymore. It will be removedin a future version
Gtk-Message: 15:39:17.315: Failed to load module “appmenu-gtk-module”
fn-swap = False

That’s what bugs me, looks like a simple ‘if then’ but doesn’t fly…

Also inconsistent quotes " are used to enclose the value when you post your scripts.

#!/bin/bash
if solaar config 1 | grep fn-swap “True”
then solaar config 1 fn-swap “false”
else solaar config 1 fn-swap “true”
fi

Exception: fn-swap: don’t know how to interpret ‘“true”’ as boolean

Rewrite the quotes.

ROFL yes, it works.

#!/bin/bash
if solaar config 1 | grep fn-swap 'True'
then solaar config 1 fn-swap 'false'
else solaar config 1 fn-swap 'true'
fi

Wow, what an idiot… Thanks dude :wink:

You’re welcome. We always need someone else to reflect back.

One slight problem, because ‘solaar config 1 | grep fn-swap’ is never ‘True’. The script only ever executes ‘else’ i.e. sets true every time.

#!/bin/bash
if solaar config 1 | grep fn-swap "True"
then solaar config 1 fn-swap "False"
else solaar config 1 fn-swap "True"
fi

Always sets to True.
Now you’ve gone back to double quotes…

OK lets go back a little.

I pointed out in post#4 a perhaps unnecessary space between = and the value in the first script you posted. I’m not using solaar btw.

Then in post#3 you posted a new script with another syntax (removed the =, went from Capital to lower case initial letter) and said it was working.

Then in posts#8 and #10, when you post your scripts, I see opening and closing double quotes instead of straight double quotes. That’s what I meant when I suggested to “rewrite your quotes”. I didn’t meant switch to single quotes. What are you using to write your scripts? It looks like an autocorrect feature of a word processing software.

solaar --help and solaar <command> --help should tell you the correct syntax.

Sure, the syntax works.
The first part fails…
❯ solaar config 1 fn-swap “false” reports Setting fn-swap to False
“true” to True.
So I wanted to do the ‘grep’ to see if False or True came up.

In terminal I can do both “false” or ‘false’ to set false. The number of quotes seems irrelevant in the command…

The issue remains that the ‘if’ condition seems indeterminate… so the ‘else’ is what gets done, not the ‘then’.

I thought the first script you posted worked with your old keyboard.

No, the old keyboard didn’t have combined keys.

This isn’t an error in the software, simply that trying to get the string to test:

if solaar config 1 | grep fn-swap 'True'
     then (echo "fx-swap is ON")
     else (echo "fx-swap is OFF @_@")

Always reports fx-swap is OFF even if I turn it on. There’s something wrong in getting the information ‘True’ to match the ‘if’ statement.

Oh! LOL
of course it is wrong… Sorry for wasting your time.

1 Like