Hello,
I'm looking into the possibility of recording the options selected when selecting the 'save as' command from the menu. I would like to make a script that keeps a record of where the user saves copies of the current document in order automate the updating of these copies with new versions later on.
I've figured out how to add an event listener when the menu item is clicked, but haven't figured out how to record what options are selected afterwards. I know that the Script Listener plugin shows this information in it's log on the desktop. My question is, is there a way to record the save as information found in this Script Listener log file, without using the Script Listener plugin? Having the script listener plugin installed all the time would generate a massive log file on the desktop, too big for regular use. If not through javascript, does anybody know of a way through the SDK?
Thanks for the help,
-Brennan
Record Save As Options
Record Save As Options
The save/saveAs event has the same info that would be recorded in the scriptlistener log. You just need to put the info from the descriptor in the event arguments.
Here is an example. Note this example does not do anything with the info and because each format has a different options descriptor this only handles jpg. But it does show how to get the info and you should be able to extend it for other formats.
Code: Select allfunction _handler(desc) {
var doc = app.activeDocument;
var format = desc.getObjectType(charIDToTypeID('As '));
var optionDesc = desc.getObjectValue(charIDToTypeID('As '));
if(format==charIDToTypeID('JPEG')) getJPEGOptions(optionDesc);
var saveFolder = desc.getPath(charIDToTypeID('In '));// if saveAs this will be a file object
};
function getJPEGOptions(desc){
if(desc.count==2) var type = 'standard';
if(desc.hasKey(charIDToTypeID('Optm'))) var type = 'optimized'
var qty = desc.getInteger(charIDToTypeID('EQlt'));
if(desc.hasKey(charIDToTypeID('Scns'))){
var type = 'progressive';
var scans = desc.getInteger(charIDToTypeID('Scns'));
}
if(desc.hasKey(charIDToTypeID('Mttc'))) var matte = typeIDToStringID(desc.getEnumerationValue(charIDToTypeID('MttC')));
if(desc.hasKey(charIDToTypeID('Clr '))){
var colorDesc = desc.getObjectValue(charIDToTypeID('Clr '));
var color = new SolidColor;
color.hsb.hue = colorDesc.getUnitDoubleValue(charIDToTypeID('H '));
color.hsb.saturation = colorDesc.getUnitDoubleValue(charIDToTypeID('Strt'));
color.hsb.brightness = colorDesc.getUnitDoubleValue(charIDToTypeID('Brgh'));
}
}
try {
if (arguments.length >= 2) {
var desc = arguments[0];
var event = arguments[1];
if (event == charIDToTypeID("save")) {
_handler(desc);
}
}
} catch (e) {
alert( "Error: " + e + ":" + e.line );
}
Here is an example. Note this example does not do anything with the info and because each format has a different options descriptor this only handles jpg. But it does show how to get the info and you should be able to extend it for other formats.
Code: Select allfunction _handler(desc) {
var doc = app.activeDocument;
var format = desc.getObjectType(charIDToTypeID('As '));
var optionDesc = desc.getObjectValue(charIDToTypeID('As '));
if(format==charIDToTypeID('JPEG')) getJPEGOptions(optionDesc);
var saveFolder = desc.getPath(charIDToTypeID('In '));// if saveAs this will be a file object
};
function getJPEGOptions(desc){
if(desc.count==2) var type = 'standard';
if(desc.hasKey(charIDToTypeID('Optm'))) var type = 'optimized'
var qty = desc.getInteger(charIDToTypeID('EQlt'));
if(desc.hasKey(charIDToTypeID('Scns'))){
var type = 'progressive';
var scans = desc.getInteger(charIDToTypeID('Scns'));
}
if(desc.hasKey(charIDToTypeID('Mttc'))) var matte = typeIDToStringID(desc.getEnumerationValue(charIDToTypeID('MttC')));
if(desc.hasKey(charIDToTypeID('Clr '))){
var colorDesc = desc.getObjectValue(charIDToTypeID('Clr '));
var color = new SolidColor;
color.hsb.hue = colorDesc.getUnitDoubleValue(charIDToTypeID('H '));
color.hsb.saturation = colorDesc.getUnitDoubleValue(charIDToTypeID('Strt'));
color.hsb.brightness = colorDesc.getUnitDoubleValue(charIDToTypeID('Brgh'));
}
}
try {
if (arguments.length >= 2) {
var desc = arguments[0];
var event = arguments[1];
if (event == charIDToTypeID("save")) {
_handler(desc);
}
}
} catch (e) {
alert( "Error: " + e + ":" + e.line );
}