command line lock screen for gnome and KDE

Do have this right for common linux installations of KDE and Gnome?

Another method for gnome.

xdg-screensaver lock
               #lock screen
               if  "$LockScreenCommand" == '1' ]];then
                    #printf "Desktop:  %s
" $XDG_CURRENT_DESKTOP
                    if  $(wmctrl -m | grep KWin) ]]; then
                         loginctl unlock-session 1
                    fi
                    if  $(wmctrl -m | grep GNOME) ]]; then     
                         gnome-screensaver-command --lock
                    fi
               fi


Hi
For gnome, nope not in current versions… look at the gsettings schema, keys and settings, seems a bit intrusive over riding a user desktop setup choice?

?? It’s detecting the current desktop and executing the right command.

dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

               #lock screen
               if  "$LockScreenCommand" == '1' ]];then
                    #printf "Desktop:  %s
" $XDG_CURRENT_DESKTOP
                    if  $(wmctrl -m | grep KWin) ]]; then
                         loginctl unlock-session
                    fi
                    if  $(wmctrl -m | grep GNOME) ]]; then     
              dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock 
                   fi
                    fi


If not this method then which method?

Hi
Shouldn’t you ask the end user (as in check their preferences) before invoking something that may have been disabled, or an option to disable in your code? I have screenlock disabled… :wink:

Err, that should be ‘=0’. Screenlock is off by default. The screenlock function works for KDE.

background scan
screen lock [option]
suspend or power off

Again, do I have that right for gnome? If don’t get an answer here, I’ll have to rely gnome users to tell me if it works.

Hi
There are multiple ways to implement screen locking in GNOME, the method you used works, then there is super+L and gsettings. What I’m saying is that your section of code potentially overrides a user setting/workflow. If you start doing lots of coded checks, especially for different desktops, it is probably more efficient to add and source a user config file, start with some defaults that the user can override if wanting to?

scanvirus was always designed from the start to not use any windowed environment (desktop). The three functions are only extras. You can use scanvirus without ever using these extra functions. Also, you can do these functions manually. Again, these commands are extra shortcuts.

I should separate the suspend and power off from send command to background. These functions are limited and are that way for a reason.

Adding the commands into the config file creates security issues.

I have checks for both gnome and kde. The config settings allows on/off of screen locking on power off and suspend.

All are optional shortcuts for KDE and Gnome. scanvirus can be used on a server with no desktop interface.

scanvirus -vf [open virus vault folder]
scanvirus -l s linux scan - suspend on complete
scanvirus -m s msin scan - suspend on complete

CFG file
Suspend or power-off then lock screen - GNOME KDE
LockScreenCommand= 0

Due to how the commands function this is easiest way for users to operate it.

If you have better way, I like to hear it.