Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[indesign][extendscript]保存毎に前回保存時のコピーを残す
#targetengine "logging"
var timeStamp = function(d){
var i,ary;
if(!d){ d = new Date() };
ary = [
d.getFullYear(),(d.getMonth()+1),d.getDate(),
d.getHours(),d.getMinutes(),d.getSeconds()
];
for(i=0,len=ary.length;i<len;i++){
ary[i] = (ary[i]<10)? '0'+ary[i]:''+ary[i];
};
return ary.join('-');
};
var docSaveWithTimeStamp = function(doc){
var saveEvent = doc.addEventListener (
'beforeSave',
function(ev){
var docFile = ev.fullName;
if(docFile){
var withTimeStamp = docFile.absoluteURI.replace(
/\.indd$/,
'_'+timeStamp(docFile.modified)+'.indd'
);
docFile.copy(withTimeStamp);
}
}
);
};
(function(){
app.addEventListener('afterNew',function(ev){docSaveWithTimeStamp(ev.target)});
app.addEventListener('afterOpen',function(ev){docSaveWithTimeStamp(ev.target)});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment