Skip to content

Instantly share code, notes, and snippets.

@FiveYellowMice
Created November 26, 2016 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiveYellowMice/ab8be8dad198bcc79f9dfd2975312d43 to your computer and use it in GitHub Desktop.
Save FiveYellowMice/ab8be8dad198bcc79f9dfd2975312d43 to your computer and use it in GitHub Desktop.
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