Reputation: 13397
I'm writing some automation scripts for Photoshop in javascript. I'd like to be able to control the zoom level in the script, preferably reading the current value, setting it to 100%, and then resetting the original value when the scrip completes. What's the best way to do this?
The only way I've found so far is to call the "actual pixels" menu command. However, this doesn't allow me to read the current value, nor set a specific zoom level that isn't 100%.
Upvotes: 3
Views: 1412
Reputation: 648
I think you can use this:
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
doMenuItem = function(item, interactive) {
var ref = new ActionReference();
ref.putEnumerated(cTID("Mn "), cTID("MnIt"), item);
var desc = new ActionDescriptor();
desc.putReference(cTID("null"), ref);
try {
var mode = (interactive != true ? DialogModes.NO : DialogModes.ALL);
executeAction(sTID("select"), desc, mode);
} catch (e) {
if (!e.message.match("User cancelled")) {
throw e;
} else {
return false;
}
}
return true;
}
doMenuItem(cTID('ActP')); // Set Zoom to 100%
doMenuItem(cTID('ZmIn')); // Zoom in on time more. (200 %)
I found the use example here, though the example is pdf so I'm not sure if that matters.
Upvotes: 1