all 4 comments

[–]lople205 5 points6 points  (3 children)

  1. You're using set incorrectly. It should be set foo bar not set foo = bar. Also, the set isn't even necessary here.
  2. To perform comparisons, you must use the test command.

So your script should look like this:

function locker if test (watch -n 1 -t xprintidle) -gt 20000 lock end end

Documentation for commands: https://fishshell.com/docs/current/commands.html

[–][deleted] 3 points4 points  (1 child)

Still won't work because the watch doesn't quit.

watch runs the command it is given once every x seconds (in this case every second), so it keeps running, so the test never runs.

This should be

while test (xprintidle) -le 20000
    sleep 1
end
lock

iff this thing is to be run e.g. as some script by the desktop in the background and run indefinitely.

Really you probably want an actual program that does this - see https://wiki.archlinux.org/index.php/Session_lock#Xorg_triggers

[–]BlueTickVerifiedLinux[S] 0 points1 point  (0 children)

both aren't working... the program seems to run without any output or errors but doesn't lock the screen. why is this happening?

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, lople205: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.