Hello,
need to auto save active Indesign (ID) CS6 to a backup folder and not save more that 10 versions of the same file. When the counter get 10 versions (V10) replace file from first version (V1).
I’ve this working right now:
tell application “Finder” to set backupPath to folder “Macintosh HD:_BackupINDD”
tell application “Adobe InDesign CS6”
try
set myFilePath to file path of active document
set myFile to full name of active document
set nuName to name of active document
tell application “Finder”
set backupFile to duplicate myFile to backupPath with replacing
end tell
end try
end tell
I’ve tried this but don’t work (this script make the same like the above, but it’s supposed to write de date on the filename).
tell application “Finder” to set backupPath to folder “Macintosh HD_BackupINDD”
tell application “Adobe InDesign CS6”
try
set myFilePath to file path of active document
set myFile to full name of active document
set cd to current date
set nuName to name of active document
set nuName to nuName & “-” & ((year of cd) & (month of cd) & (day of cd) as string)
set nuName to nuName & “-” & (time of cd) as string
tell application “Finder”
set backupFile to duplicate myFile to backupPath
set name of backupFile to nuName
end tell
save active document
on error
save active document
end try
end tell
I’m thinking to use this JSP (it’s working)
//DESCRIPTION:Copies the current document to a backup-location before saving
var desktop_path = Folder.desktop.toString();
// var backup_path = “/someFolder/someSubfolder/backupLocation”;
var backup_path = desktop_path+“/backup”
if (Folder(backup_path.exists == false )) {
Folder(backup_path).create();
}
if (app.documents.length > 0) {
main();
}
function main() {
var doc = app.activeDocument;
try {
if (doc.saved == true) {
var doc_file = doc.fullName;
var doc_name = doc.name;
var now = new Date();
var datestamp = now.getFullYear().toString() + " " + two_digit(now.getMonth()+1) + " " + two_digit(now.getDate());
var timestamp = two_digit(now.getHours()) + two_digit(now.getMinutes()) + two_digit(now.getSeconds());
var target_folder = Folder(backup_path + “/” + datestamp);
if (target_folder.exists == false ) {target_folder.create(); }
var target_file = target_folder.toString() + “/” + timestamp + “_” + doc_name;
if (doc_file.copy(target_file) == false) {
alert(“Backup error\rCould not create backup copy.”);
}
}
} catch (e) {
alert(e);
}
doc.save();
function two_digit(n) {
if (n < 10) {
return "0" + n.toString();
} else {
return n.toString();
}
}
}
And then i read somewhere that i can use a JSP script and call a AppleScript. I googlit and found this sintax to include on JSP to call a Applescript:
var appleScript = new File(‘~/Desktop/apple-script-file.app’);
if (appleScript.exists) appleScript.execute();
Finally, i found a Applescript to delete files after x days, but is not what i want either.
– Set the age of files that you want to purge from your downloads folder
set modDate to (30)
– Get current user’s name
tell application “System Events”
set currentUser to (name of current user)
end tell
– Check downloads folder and move files to the trash that are older than N days.
tell application “Finder”
try
delete (every item of folder “Downloads” of folder currentUser of folder “Users” of startup disk whose modification date is less than ((current date)) - modDate * days)
end try
end tell
– Display a dialog window asking whether to empty trash or not
set theButton to button returned of (display dialog “Would you like to empty the trash?” with icon caution buttons {“Empty Trash”, “Cancel”} default button “Cancel” giving up after 10)
if theButton is “Empty Trash” then
tell application “Finder”
empty trash
end tell
end if
Anyone can help? pLease!
Regards
Ricardo