﻿

function d2(s)
{
    if(s.length < 2)
        s = "0" + s;
    return s;
}

var photologDir = "/Volumes/reflections_iii/projects_5_2015/2015_Metareal/Photolog/";

function fileExists(f)
{
    
}

var d = new Date();
var yS = "" + d.getFullYear();
var mS = d2("" + (1 + d.getMonth()));
var dS = d2("" + d.getDate());

var dateS = yS + "-" + mS + "-" + dS;
var jpg = ".jpg";
var fileS = photologDir + dateS + jpg;

var f = new File(fileS);
var letter = 98; // 'b'
while(f.exists)
{
    var fileS = photologDir + dateS + String.fromCharCode(letter++) + jpg;
    f = new File(fileS);
}

// finally save it

var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = false ;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 7;

app.activeDocument.saveAs(f, jpgSaveOptions, true, Extension.LOWERCASE);

alert("wrote " + f);

app.open(f);

// The end. Got writ.