Skip to content

Instantly share code, notes, and snippets.

@kanemu
Created September 3, 2011 14:04
Show Gist options
  • Save kanemu/1191232 to your computer and use it in GitHub Desktop.
Save kanemu/1191232 to your computer and use it in GitHub Desktop.
[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