Created
November 26, 2016 05:28
-
-
Save FiveYellowMice/ab8be8dad198bcc79f9dfd2975312d43 to your computer and use it in GitHub Desktop.
Automatically delete old screenshots. Run as a systemd timer or cron job.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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