Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically delete old screenshots. Run as a systemd timer or cron job.
#!/usr/bin/env ruby
SCREENSHOTS_DIR = ENV['SCREENSHOTS_DIR'] ||
ENV['HOME'] + '/Pictures/Screenshots'
MAXIMUM_TIME = ENV['MAXIMUM_TIME'] ||
60 * 60 * 24 # 1 day
#######################################
#
# WARNING
# This script may misbehave if SCREENSHOTS_DIR contains glob special characters.
#
if ENV['XDG_SESSION_DESKTOP'] != 'KDE'
exit 1
end
files = Dir.glob(SCREENSHOTS_DIR + '/**/*')
files.each do |file|
time = [File.ctime(file), File.mtime(file)].max
elapsed = Time.now - time
if elapsed > MAXIMUM_TIME
puts "Deleting file #{file[(SCREENSHOTS_DIR.length + 1)..-1]} ..."
system 'kioclient5', 'move', file, 'trash:/'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.