Some notes before the code. I think the easiest way to work with presets is by name and embedded the preset in the script. But the preset names need to be unique. If the user already has a tool preset with the same name this script will use the first name match if finds. File.prototype.writeByte = function(b) { this.write(String.fromCharCode(b)); }; function loadPreset(file){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset" ) ); ref.putEnumerated( charIDToTypeID( "capp" ),charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" )); desc.putReference( charIDToTypeID( "null" ), ref ); desc.putPath( charIDToTypeID( "T " ), new File( file ) ); desc.putBoolean( charIDToTypeID( "Appe" ), true ); executeAction(charIDToTypeID( "setd" ), desc, DialogModes.NO ); }; function selectTool(tool) { var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putClass( app.stringIDToTypeID(tool) ); desc.putReference( app.charIDToTypeID('null'), ref ); executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO ); }; function selectPreset(presetName){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putName( stringIDToTypeID( "toolPreset" ), presetName ); desc.putReference( charIDToTypeID( "null" ), ref ); executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); }; var kSpotHealingBrush = 'spotHealingBrushTool'; // tool preset names should be unique. This example only uses one preset // but the embedded preset could have as many presets as you need. var toolPresetName = 'Spot Healing Brush Tool Hard Round 19 1'; selectTool(kSpotHealingBrush); try{ selectPreset(toolPresetName);// if a preset with that name already exists use it }catch(e){// else load the preset(s) and try again // optional - create new preset file from embedded data and load. Delete all lines in catch if not using fallback // data from a .tpl file. This data is for one preset but it could contain as many as you need var toolPresetBinaryArray = [56,66,84,80,0,0,0,3,0,0,0,1,56,66,73,77,116,112,116,112,0,0,4,124,0,0,0,1,0,0,0,40,0,83,0,112,0,111,0,116,0,32,0,72,0,101,0,97,0,108,0,105,0,110,0,103,0,32,0,66,0,114,0,117,0,115,0,104,0,32,0,84,0,111,0,111,0,108,0,32,0,72,0,97,0,114,0,100,0,32,0,82,0,111,0,117,0,110,0,100,0,32,0,49,0,57,0,32,0,49,0,0,0,0,0,16,0,0,0,1,0,0,0,0,0,20,115,112,111,116,72,101,97,108,105,110,103,66,114,117,115,104,84,111,111,108,0,0,0,25,0,0,0,4,102,108,111,119,108,111,110,103,0,0,0,100,0,0,0,0,77,100,32,32,101,110,117,109,0,0,0,0,66,108,110,77,0,0,0,0,78,114,109,108,0,0,0,0,79,112,99,116,108,111,110,103,0,0,0,100,0,0,0,0,66,114,115,104,79,98,106,99,0,0,0,1,0,0,0,0,0,13,99,111,109,112,117,116,101,100,66,114,117,115,104,0,0,0,8,0,0,0,0,68,109,116,114,85,110,116,70,35,80,120,108,64,51,0,0,0,0,0,0,0,0,0,0,72,114,100,110,85,110,116,70,35,80,114,99,64,89,0,0,0,0,0,0,0,0,0,0,65,110,103,108,85,110,116,70,35,65,110,103,0,0,0,0,0,0,0,0,0,0,0,0,82,110,100,110,85,110,116,70,35,80,114,99,64,89,0,0,0,0,0,0,0,0,0,0,83,112,99,110,85,110,116,70,35,80,114,99,64,57,0,0,0,0,0,0,0,0,0,0,73,110,116,114,98,111,111,108,1,0,0,0,5,102,108,105,112,88,98,111,111,108,0,0,0,0,5,102,108,105,112,89,98,111,111,108,0,0,0,0,14,117,115,101,84,105,112,68,121,110,97,109,105,99,115,98,111,111,108,1,0,0,0,5,102,108,105,112,88,98,111,111,108,0,0,0,0,5,102,108,105,112,89,98,111,111,108,0,0,0,0,15,98,114,117,115,104,80,114,111,106,101,99,116,105,111,110,98,111,111,108,0,0,0,0,15,109,105,110,105,109,117,109,68,105,97,109,101,116,101,114,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,16,109,105,110,105,109,117,109,82,111,117,110,100,110,101,115,115,85,110,116,70,35,80,114,99,64,57,0,0,0,0,0,0,0,0,0,9,116,105,108,116,83,99,97,108,101,85,110,116,70,35,80,114,99,64,105,0,0,0,0,0,0,0,0,0,0,115,122,86,114,79,98,106,99,0,0,0,1,0,0,0,0,0,0,98,114,86,114,0,0,0,4,0,0,0,0,98,86,84,121,108,111,110,103,0,0,0,2,0,0,0,0,102,83,116,112,108,111,110,103,0,0,0,25,0,0,0,6,106,105,116,116,101,114,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,0,77,110,109,32,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,13,97,110,103,108,101,68,121,110,97,109,105,99,115,79,98,106,99,0,0,0,1,0,0,0,0,0,0,98,114,86,114,0,0,0,4,0,0,0,0,98,86,84,121,108,111,110,103,0,0,0,0,0,0,0,0,102,83,116,112,108,111,110,103,0,0,0,25,0,0,0,6,106,105,116,116,101,114,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,0,77,110,109,32,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,17,114,111,117,110,100,110,101,115,115,68,121,110,97,109,105,99,115,79,98,106,99,0,0,0,1,0,0,0,0,0,0,98,114,86,114,0,0,0,4,0,0,0,0,98,86,84,121,108,111,110,103,0,0,0,0,0,0,0,0,102,83,116,112,108,111,110,103,0,0,0,25,0,0,0,6,106,105,116,116,101,114,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,0,77,110,109,32,85,110,116,70,35,80,114,99,0,0,0,0,0,0,0,0,0,0,0,12,117,115,101,66,114,117,115,104,80,111,115,101,98,111,111,108,0,0,0,0,24,117,115,101,80,114,101,115,115,117,114,101,79,118,101,114,114,105,100,101,115,83,105,122,101,98,111,111,108,0,0,0,0,27,117,115,101,80,114,101,115,115,117,114,101,79,118,101,114,114,105,100,101,115,79,112,97,99,105,116,121,98,111,111,108,0,0,0,0,9,117,115,101,76,101,103,97,99,121,98,111,111,108,0,0,0,0,0,83,116,109,83,98,111,111,108,0,0,0,0,0,83,116,109,66,98,111,111,108,0,0,0,0,0,83,116,109,73,98,111,111,108,0,0,0,0,0,83,116,109,65,98,111,111,108,0,0,0,0,0,73,109,112,115,98,111,111,108,0,0,0,0,0,83,109,112,83,101,110,117,109,0,0,0,0,83,109,112,84,0,0,0,0,83,114,99,78,0,0,0,0,83,109,109,83,101,110,117,109,0,0,0,0,83,109,109,84,0,0,0,0,67,110,116,87]; var tempPresetFile = new File(Folder.temp+'/spotHealingBrushPreset.tpl'); tempPresetFile.encoding = 'BINARY'; tempPresetFile.open("w"); tempPresetFile.seek(0, 0); for(i=0;i<toolPresetBinaryArray.length;i++){ tempPresetFile.writeByte(toolPresetBinaryArray); } tempPresetFile.close(); loadPreset(tempPresetFile); selectPreset(toolPresetName);// should work now the preset is loaded } To get the data from the .tpl file you need to create a preset with a unique name. In the Preset Manager you select the preset(s) and save a new set. Then run this script in ESTK. The needed data will be in the console. Copy and paste into the main script replacing the data in the toolPresetBinaryArray array. Note this only needs to be done once to get the data. Once you have the data it is no longer needed by the main script. File.prototype.readByte = function() { return this.read(1).charCodeAt(0); }; // run in ExtendScript Toolkit // replace this file reference with the path to your preset file var file = new File("~/desktop/Untitled Tool Presets.tpl"); var tag = new Array file.open("r"); file.encoding = 'BINARY'; file.seek(0, 0); for(i=0;i<file.length;i++){ tag.push(file.readByte()); } $.writeln(tag); file.close(); By embedding the preset you don't have to worry about distributing and installing the .tpl file with your script.
... View more