Created
January 9, 2016 06:40
-
-
Save gregschoen/136906719adab44ea6a0 to your computer and use it in GitHub Desktop.
Quick and dirty script to keep my Screenshot folder clean and properly named.
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/php | |
<?php | |
date_default_timezone_set("America/Chicago"); | |
$who = trim(`whoami`); | |
$base = "/Users/{$who}/Dropbox/Screenshots/"; | |
$files = glob("{$base}*.png"); | |
foreach($files as $file) | |
{ | |
$original = $file; | |
if(preg_match("/Screenshot (.*)\.png/",$file,$match)) | |
{ | |
$dt = str_replace(" at "," ",$match[1]); | |
if(strpos($dt," (2)")) | |
{ | |
$dt = str_replace(" (2)","",$dt); | |
$timestamp = strtotime($dt) + 1; | |
} | |
else | |
$timestamp = strtotime($dt); | |
$datetime = date("Y-m-d H.i.s",$timestamp); | |
if($datetime) | |
{ | |
// crushing PNG with PNGquant | |
exec("pngquant " . escapeshellarg($original) . " --output " . escapeshellarg($base.$datetime.".png"), $output, $code); | |
if($code == 0) | |
unlink($original); | |
else | |
echo "Something went wrong! Error Code: $code\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment