Hi,
I am familiar with AppleScripting Photoshop, but not javascript. I (ideally) want to write a script to delete all tools presets from the preset manager whose names start with "Web ". If that's not possible, I'd like to be able to delete all the tool presets, leaving other presets (ie brushes, swatches, etc) intact. I didn't see a way to do either of these via AppleScript.
Thanks to other posts on this board, I got as far as finding the presets I want to delete:
Code: Select allvar Presets = getPresetList();
for(var presetname in Presets){
$.writeln(Presets[presetname]);
}
function getPresetList(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var appDesc = executeActionGet(ref);
// Get the list of presets from the preset manager
var presets = appDesc.getList(stringIDToTypeID('presetManager'));
// Make an empty list of preset names
var presetNames=[];
var toolpresets = presets.getObjectValue(7)
var toolpresetnames = toolpresets.getList(charIDToTypeID ('Nm '));
for (var i = 0; i < toolpresetnames.count; i++) {
var str = toolpresetnames.getString(i);
if (str.indexOf ("Web ", 0) != -1)
{
presetNames.push(str);
// something here to delete the preset if that's possible?
}
}
return presetNames;
}
But I am a bit stuck on how to remove the presets. Can anyone help?
Thanks a lot!
Remove specific Tool Presets
Remove specific Tool Presets
OK so I worked out how to remove by index
Code: Select allfunction killcrop(toolindex){
$.writeln("Deleting index:", toolindex);
var deleteAction = charIDToTypeID( "Dlt " );
var myActionDescriptor = new ActionDescriptor();
var myNull = charIDToTypeID( "null" );
var myActionList = new ActionList();
var myActionRef = new ActionReference();
var toolpreset = stringIDToTypeID( "toolPreset" );
myActionRef.putIndex( toolpreset, toolindex);
myActionList.putReference( myActionRef );
myActionDescriptor.putList( myNull, myActionList );
// Now perform the action
executeAction( deleteAction, myActionDescriptor, DialogModes.NO );
};
Obviously as you delete crops the indices of the remaining crops shift - so is there an easy way to delete by name, or interrogate item for current index? I've worked around my stupidity for now, but would be nice to know how to do it properly!
Code: Select allfunction killcrop(toolindex){
$.writeln("Deleting index:", toolindex);
var deleteAction = charIDToTypeID( "Dlt " );
var myActionDescriptor = new ActionDescriptor();
var myNull = charIDToTypeID( "null" );
var myActionList = new ActionList();
var myActionRef = new ActionReference();
var toolpreset = stringIDToTypeID( "toolPreset" );
myActionRef.putIndex( toolpreset, toolindex);
myActionList.putReference( myActionRef );
myActionDescriptor.putList( myNull, myActionList );
// Now perform the action
executeAction( deleteAction, myActionDescriptor, DialogModes.NO );
};
Obviously as you delete crops the indices of the remaining crops shift - so is there an easy way to delete by name, or interrogate item for current index? I've worked around my stupidity for now, but would be nice to know how to do it properly!