Follow your company security guidelines! :D
Sometimes you need to have a process running on the background but your laptop policies (automatic lock) are the problem. So you need to have a backup plan for this cases, here's where this solution gets interesting.
Moves your mouse certain pixels randomly during an especific period of time and certain interval so the computer detects interaction and the lock screen is never reached!
- Ruby 2.7+
- https://github.com/kosmaks/rumouse installed
- A terminal
- Privileges (in case of mac, for example) to control the mouse (usually under accesibility)
Save the script
described below as do_not_lock_the_screen.rb
on your computer and grant execution privileges
chmod +x do_not_lock_the_screen.rb
This can be also executed directly using the ruby interpreter!
#!/usr/bin/env ruby
require 'rumouse'
require 'time'
require 'logger'
require 'optparse'
ARGV << '-h' if ARGV.empty?
Options = Struct.new(:name)
program_options = {}
logger = Logger.new(STDOUT)
logger.level = Logger::WARN
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: do_not_block_me.rb [options]"
opts.on('-i', '--script-interval [VALUE]', Integer, 'Wait interval in seconds') do |script_interval|
program_options[:script_interval] = script_interval
end
opts.on('-d', '--script-duration [VALUE]', Integer, 'script duration in seconds') do |script_duration|
program_options[:script_duration] = script_duration
end
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
program_options[:verbose] = v
if v then
logger.level = Logger::DEBUG
end
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end
option_parser.parse!
mouse = RuMouse.new
now = Time.now
random_boolean = [true, false]
loop do
if program_options[:script_duration] > 0 then
logger.warn "sleeping #{program_options[:script_interval]} seconds ... "
sleep(program_options[:script_interval])
break if Time.now > (now + program_options[:script_duration])
logger.debug "Remaining time: #{((now + program_options[:script_duration]) - Time.now).to_i}"
end
rand_position = rand(10)
logger.debug "rand_position: #{rand_position}"
if [true, false].sample
rand_position = rand_position * -1
end
mouse_pos = mouse.position
new_pos = {
:x => (mouse_pos[:x] + rand_position),
:y => (mouse_pos[:y] + rand_position)
}
puts "Moving mouse from:#{mouse_pos}, to:#{new_pos}"
mouse.move new_pos[:x], new_pos[:y]
end
Execute the script
./do_not_lock_the_screen.rb --script-interval 10 --script-duration 300