Copy link to clipboard
Copied
Hello everybody, I am new to scripting and I am trying to load some presets (actions, brushes, styles, shapes) in order to be the active/default sets in Photoshop.
I have managed to do it with the ScriptListener, but he "follows" the exact path of my computer in order to load and activate the presets. Of course that will cause problems once the script is used outside my computer.
I have managed to direct the script to read the preset folder without following the exact local path (example: app.path+'/Presets/Actions/ActionsSet.atn), but how to activate this set as the default set for the user?
Any help will be appreciated!
Copy link to clipboard
Copied
Hey it's me again. I figured out how to load a preset through a better path and I hope that will help someone else.
Lets say that I want to load a set of Actions (ActionsSet.atn):
function myActions() {
var newActionsPath = app.path+'/Presets/Actions/ActionSet.atn';
app.load(new File(newActionsPath);
}
myActions();
That will load the appropriate preset to user's Photoshop no matter the version of Ps or the architecture of the computer (PC, MAC). But I need a couple of things in case somebody knows. How can I make a "load and replace" instead of just "load" (specially for styles and custom shapes) and how to make an "if" statement to check if the presets are already loaded and not load them again.
Thank you in advance!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you for your help my friend but this scrips unloads the action set, doesn't load action sets or check for an already loaded action set.
Copy link to clipboard
Copied
You can normally only count one selecting Tool preset for the current active tool. You can not set Photoshop UI Tools preset to all tools. So you can not count on it being able to load and named tool preset. You need to select the tool first and that the preset. If you always load the preset files you will have it loaded many times. It is better to use a try catch try to select the preset if it fails to select load the presets and then select the preset. Presets can also be depleted the try catch should always work..
Cycle tool presets
/* ================================================================================= Cycling Forward and Backward through Sets of Tool Presets ===================================================================================== 2017 John J. McAssey (JJMack) ===================================================================================== Naming Your Script so that it identify the tool and Presets Set will be helpful. Copy this script to a new Name for each set of presets you want to cycle through. Run that script via shortcut keys. Set two Shortcuts keys F(n) Forward Modifier+F(n) Backward There are three required parameters for the cycling function: 1.) Correct Photoshop Tools Name 2.) Presets Set file name the * part of the *.tpl file The *.tpl file must reside in the scripts folder 3.) Array of preset names in your desired cycling order ===================================================================================== Note: This script only deals with Tool Preset files .tpl for tools preset are easily reset back to Adobe's defaults using the Preset manager. Tool presets may require other Photoshop add-ons like brush .abr, patterns .pat, swatch .aco, etc files to also be loaded this script will not load them this script will only load .tpl files if there is a need too. You must add what your presets require to Photoshop ================================================================================== */ //@show include //@include "cycleTool.jsx" #target photoshop; app.bringToFront(); // Required three parameters tool,Set,list var tool = 'paintbrushTool'; // Photoshop Tool name your Presets set is for. Only one tool's presets // This sample script presets were downloaded from DeviantArt brushes "The Sketch Arsenal" "the_sketch_arsenal_by_thatld.tpl"" // http://thatld.deviantart.com/art/The-Sketch-Arsenal-161678023 Download link on Top Right of the Page not the one on the bottom var presetSet = 'the_sketch_arsenal_by_thatld'; // Presets set name *.tpl file need to be same folder as this Photoshop script. var presetNames = [ // Preset names list start. Presets you want to cycle through. Set can have more. 'Color Brush - Flat', 'Color Brush - Magic Edge', 'Color Pencil - Hard', 'Color Pencil - Soft', 'Drawing Pencil - B Lead', 'Drawing Pencil - Blue Line', 'Drawing Pencil - H Lead', 'Linework Pen - Fine', 'Marker - Lower the Flow to Dry', 'Shading Brush - Pressure Hold', 'Shading Brush - Soft Texture', 'Shading Pencil - General', 'Shading Pencil - Hard', 'Shading Pencil - Soft', 'Sketch Pencil - H Lead', 'Sketch Pencil - The Ultimate!', 'Watercolor Brush - General' ]; // Presets names list end. Order the way you want to cycle through them // End Required Parameters cycleTool(tool,presetSet,presetNames); // Cycle Forward and Backward through tool presets set names // End of Script //=============================================================================================================================================// /* Photoshop tool names 'moveTool' 'cloneStampTool' 'typeCreateOrEditTool' 'artboardTool' 'marqueeRectTool' 'patternStampTool' 'typeVerticalCreateOrEditTool' 'perspectiveCropTool' 'marqueeEllipTool' 'historyBrushTool' 'typeCreateMaskTool' 'eyedropperTool' 'marqueeSingleRowTool' 'artBrushTool' 'typeVerticalCreateMaskTool' '3DMaterialSelectTool' 'marqueeSingleColumnTool' 'eraserTool' 'pathComponentSelectTool' 'lassoTool' 'backgroundEraserTool' 'directSelectTool' 'polySelTool' 'magicEraserTool' 'rectangleTool' 'magneticLassoTool' 'gradientTool' 'roundedRectangleTool' 'quickSelectTool' 'bucketTool' 'ellipseTool' 'magicWandTool' 'blurTool' 'polygonTool' 'cropTool' 'sharpenTool' 'lineTool' 'sliceTool' 'smudgeTool' 'customShapeTool' 'sliceSelectTool' 'dodgeTool' 'textAnnotTool' 'spotHealingBrushTool' 'burnInTool' 'soundAnnotTool' 'magicStampTool' 'saturationTool' 'eyedropperTool' 'patchSelection' 'penTool' 'colorSamplerTool' 'redEyeTool' 'freeformPenTool' 'rulerTool' 'paintbrushTool' 'addKnotTool' 'handTool' 'pencilTool' 'deleteKnotTool' 'zoomTool' 'colorReplacementBrushTool' 'convertKnotTool' 'wetBrushTool' */
/* ================================================================================= Cycling Forward and Backward through Sets of Tool Presets ===================================================================================== 2017 John J. McAssey (JJMack) ===================================================================================== Naming Your Script so that it identify the tool and Presets Set will be helpful. Copy this script to a new Name for each set of presets you want to cycle through. Run that script via shortcut keys. Set two Shortcuts keys F(n) Forward Modifier+F(n) Backward There are three required parameters for the cycling function: 1.) Correct Photoshop Tools Name 2.) Presets Set file name the * part of the *.tpl file The *.tpl file must reside in the scripts folder 3.) Array of preset names in your desired cycling order ===================================================================================== Note: This script only deals with Tool Preset files .tpl for tools preset are easily reset back to Adobe's defaults using the Preset manager. Tool presets may require other Photoshop add-ons like brush .abr, patterns .pat, swatch .aco, etc files to also be loaded this script will not load them this script will only load .tpl files if there is a need too. You must add what your presets require to Photoshop ================================================================================== */ // =================================================== Main function ======================================================== // function cycleTool(toolName,toolPresetSet,toolPresetNames){ // alert("CycleTool"); if (currentToolName()!=toolName) { // if user is switching tools try to else switch tool preset try {selectTool(toolName);} // Insure the tool is select so preset can be selected catch(e) {alert("Unable to Select the Tool "+toolName); return;} // Tool name wrong or unavailable if (app.toolSupportsBrushes(app.currentTool)) app.runMenuItem(charIDToTypeID(('TglB'))); //Toggle Brush Palette return; // Just switch to the tools current setting } var desc = new ActionDescriptor(); // Set up Photoshop to remember variables try {var desc = app.getCustomOptions('Cycle'+toolPresetSet);} // Try to get CustomOption for cycling this tool presets set catch(e){ // Each Photoshop session this should fail first time reset try {selectToolPreset(toolPresetNames[0]);} // Insure Tool Presets Set has been loaded catch(e) { // Will fail if tools presets set is not loaded if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set try {selectToolPreset(toolPresetNames[0]);} // Load sets first preset catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[0]); return;} // Failed to select preset } else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set } desc.putInteger(0,0); // This line save the variable while Photoshop is open, app.putCustomOptions('Cycle'+toolPresetSet,desc,false ); // Initialize presets set CustomOption for cycling desc = app.getCustomOptions('Cycle'+toolPresetSet); // Get CustomOption Cycle starting point } var presetNumber = desc.getInteger(0); // Get the preset index if (ScriptUI.environment.keyboardState.ctrlKey||ScriptUI.environment.keyboardState.altKey|| ScriptUI.environment.keyboardState.shiftKey) { // Previous preset if Ctrl or Alt or Shift key is down presetNumber = presetNumber-2; // Back up two preset for it will be bumped one if (presetNumber<0){presetNumber=toolPresetNames.length-1;} // Set preset index to the end of the list } if (presetNumber<toolPresetNames.length){desc.putInteger(0,presetNumber+1);} // Update preset index number else {presetNumber=0; desc.putInteger(0,1);} // Reset preset index pointer to the begging of the list app.putCustomOptions('Cycle'+toolPresetSet,desc,false); // Put Update the Custom option try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset catch(e) { if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set Tool presets may have reset try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[presetNumber]); return;} // Failed to select } else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set } }; // =================================================== Helper functions ===================================================== // function selectTool(tool) { var desc9 = new ActionDescriptor(); var ref7 = new ActionReference(); ref7.putClass( app.stringIDToTypeID(tool) ); desc9.putReference( app.charIDToTypeID('null'), ref7 ); executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO ); }; function selectToolPreset(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 ); } function loadToolPresetSet(SetName) { returncode = true; var scriptLocation = String(findScript()); var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ; var SetFile = new File(path + SetName + ".tpl"); // Requited to be in the script's folder if (!SetFile.exists) { returncode = false; } else { 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( SetFile ) ); desc.putBoolean( charIDToTypeID( "Appe" ), true ); try {executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );} catch(e) { returncode = false; } } return returncode ; } function findScript() {// Find the location where this script resides var where = ""; try { FORCEERROR = FORCERRROR;} catch(err) { where = File(err.fileName);} return where ; } function currentToolName() { var ref = new ActionReference(); ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool")); ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); var applicationDesc = executeActionGet(ref); //alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool")))); return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool")))); } /* Photoshop tool names 'moveTool' 'cloneStampTool' 'typeCreateOrEditTool' 'artboardTool' 'marqueeRectTool' 'patternStampTool' 'typeVerticalCreateOrEditTool' 'perspectiveCropTool' 'marqueeEllipTool' 'historyBrushTool' 'typeCreateMaskTool' 'eyedropperTool' 'marqueeSingleRowTool' 'artBrushTool' 'typeVerticalCreateMaskTool' '3DMaterialSelectTool' 'marqueeSingleColumnTool' 'eraserTool' 'pathComponentSelectTool' 'lassoTool' 'backgroundEraserTool' 'directSelectTool' 'polySelTool' 'magicEraserTool' 'rectangleTool' 'magneticLassoTool' 'gradientTool' 'roundedRectangleTool' 'quickSelectTool' 'bucketTool' 'ellipseTool' 'magicWandTool' 'blurTool' 'polygonTool' 'cropTool' 'sharpenTool' 'lineTool' 'sliceTool' 'smudgeTool' 'customShapeTool' 'sliceSelectTool' 'dodgeTool' 'textAnnotTool' 'spotHealingBrushTool' 'burnInTool' 'soundAnnotTool' 'magicStampTool' 'saturationTool' 'eyedropperTool' 'patchSelection' 'penTool' 'colorSamplerTool' 'redEyeTool' 'freeformPenTool' 'rulerTool' 'paintbrushTool' 'addKnotTool' 'handTool' 'pencilTool' 'deleteKnotTool' 'zoomTool' 'colorReplacementBrushTool' 'convertKnotTool' 'wetBrushTool' */
/* ================================================================================= Cycling Forward and Backward through Sets of Tool Presets =====================================================================================2017 John J. McAssey (JJMack)=====================================================================================Naming Your Script so that it identify the tool and Presets Set will be helpful. Copy this script to a new Name for each set of presets you want to cycle through. Run that script via shortcut keys. Set two Shortcuts keys F(n) Forward Modifier+F(n) Backward There are three required parameters for the cycling function: 1.) Correct Photoshop Tools Name 2.) Presets Set file name the * part of the *.tpl file The *.tpl file must reside in the scripts folder 3.) Array of preset names in your desired cycling order=====================================================================================Note: This script only deals with Tool Preset files .tpl for tools preset are easily reset back to Adobe's defaults using the Preset manager. Tool presets may require other Photoshop add-ons like brush .abr, patterns .pat, swatch .aco, etc files to also be loaded this script will not load them this script will only load .tpl files if there is a need too. You must add what your presets require to Photoshop================================================================================== *///@show include//@include "cycleTool.jsx"
#target photoshop;app.bringToFront();// Required three parameters tool,Set,listvar tool = 'paintbrushTool'; // Photoshop Tool name your Presets set is for. Only one tool's presets// This sample script presets were downloaded from DeviantArt brushes "The Sketch Arsenal" "the_sketch_arsenal_by_thatld.tpl""// http://thatld.deviantart.com/art/The-Sketch-Arsenal-161678023 Download link on Top Right of the Page not the one on the bottomvar presetSet = 'the_sketch_arsenal_by_thatld'; // Presets set name *.tpl file need to be same folder as this Photoshop script.var presetNames = [ // Preset names list start. Presets you want to cycle through. Set can have more. 'Color Brush - Flat', 'Color Brush - Magic Edge', 'Color Pencil - Hard', 'Color Pencil - Soft', 'Drawing Pencil - B Lead', 'Drawing Pencil - Blue Line', 'Drawing Pencil - H Lead', 'Linework Pen - Fine', 'Marker - Lower the Flow to Dry', 'Shading Brush - Pressure Hold', 'Shading Brush - Soft Texture', 'Shading Pencil - General', 'Shading Pencil - Hard', 'Shading Pencil - Soft', 'Sketch Pencil - H Lead', 'Sketch Pencil - The Ultimate!', 'Watercolor Brush - General' ]; // Presets names list end. Order the way you want to cycle through them// End Required Parameters cycleTool(tool,presetSet,presetNames); // Cycle Forward and Backward through tool presets set names// End of Script//=============================================================================================================================================///* Photoshop tool names'moveTool' 'cloneStampTool' 'typeCreateOrEditTool' 'artboardTool''marqueeRectTool' 'patternStampTool' 'typeVerticalCreateOrEditTool' 'perspectiveCropTool''marqueeEllipTool' 'historyBrushTool' 'typeCreateMaskTool' 'eyedropperTool' 'marqueeSingleRowTool' 'artBrushTool' 'typeVerticalCreateMaskTool' '3DMaterialSelectTool''marqueeSingleColumnTool' 'eraserTool' 'pathComponentSelectTool''lassoTool' 'backgroundEraserTool' 'directSelectTool''polySelTool' 'magicEraserTool' 'rectangleTool''magneticLassoTool' 'gradientTool' 'roundedRectangleTool''quickSelectTool' 'bucketTool' 'ellipseTool''magicWandTool' 'blurTool' 'polygonTool''cropTool' 'sharpenTool' 'lineTool''sliceTool' 'smudgeTool' 'customShapeTool''sliceSelectTool' 'dodgeTool' 'textAnnotTool''spotHealingBrushTool' 'burnInTool' 'soundAnnotTool''magicStampTool' 'saturationTool' 'eyedropperTool''patchSelection' 'penTool' 'colorSamplerTool''redEyeTool' 'freeformPenTool' 'rulerTool''paintbrushTool' 'addKnotTool' 'handTool''pencilTool' 'deleteKnotTool' 'zoomTool''colorReplacementBrushTool' 'convertKnotTool' 'wetBrushTool' */
Copy link to clipboard
Copied
Thank you JJMack for your help! When I apply the script from the ScriptListener I am able to import right away almost all the assets that I need. The "Styles & Custom Shapes" are loaded into photoshop only once (not repeatedly) every time I run the script. It's like I selected the "Replace Shapes... or Replace Styles...".
Unfortunately the same thing doesn't apply with brushes, I get new copies of the same set once I re-run the script.
About the Action Set, it doesn't get loaded into Photoshop through the script from the ScriptListener. I load the Action Set with the help of the script I posted ealier, but I get (as you wrote me), repeatedly copies of the set, every time I run the script.
So far, I figured out how to import and activate as default sets the Custom Shapes & Styles. But I haven't figured out yet how to import and not repeat this action for Brushes and Actions. I need a "Replace.." kind command for those two in order to work properly.
Thank you for your help!!
Copy link to clipboard
Copied
#target photoshop;
main();
/////////////////////////////////////////
// Replace Action Set //
/////////////////////////////////////////
function main(){
atnFile = File.openDialog("Please select ActionSet.","ATN File:*.atn");
if(!atnFile.exists) return;
var Name = decodeURI(atnFile.name).replace(/\.[^\.]+$/, "");
var actionList =getActionSets();
var rex = new RegExp;
rex="^" + Name ;
for(var d in actionList){
var str = decodeURI(actionList
).toString(); if(str.match(rex,"i")) unLoadAction(actionList
); }
app.load(atnFile);
};
function unLoadAction(aSet){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "ASet" ), decodeURI(aSet));
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
};
function getActionSets(){
var aSets=[];
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("ASet"), 1);
var desc = executeActionGet(ref);
var Count = desc.getInteger(stringIDToTypeID("count")) + 1;
for(var t=1; t<=Count; t++){
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("ASet"), t);
var desc = executeActionGet(ref);
var actName = desc.getString(charIDToTypeID("Nm "));
aSets.push(actName);
}
return aSets;
};
Copy link to clipboard
Copied
Very helpful script, thank you very much! I will use it sure for something else. I should explain better that the assets I want to bring as default (Brushes, Actions, Custom Shapes & Styles) are already in Photoshop (they are installed in the presets folder). So I can see those inside the program. I need to select, activate, replace the default sets (if it's possible) and not duplicate each time I run the script.
Thank you!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Bonjour Dominique!
Thank you for you comment. Indeed the Workspace installation is something that also bugs me, I was going to create a batch file for that, but I will try and use your idea instead.
The reason I would like to bring those assets (brushes, actions, styles & C.Shapes) as defaults with a script is that even-though someone has a Workspace with specific panels and sets selected in Photoshop, once the program crashes or the computer shuts down unexpectedly, the sets are gone and I have to re-bring them as defaults (happens a lot with Actions). That's why I need a script that brings everything back. It will make user's life easier.
Merci!
Copy link to clipboard
Copied
I use 3 workspace backups with keyboard shortcuts and tools!
And I'm using this one to reset everything to zero :
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idworkspace = stringIDToTypeID( "workspace" );
ref1.putName( idworkspace, "HUN" );
desc1.putReference( idnull, ref1 );
executeAction( idslct, desc1, DialogModes.NO );
Copy link to clipboard
Copied
I understand that this script resets a specific W/S to the original (saved) version (it produces an error in the 8th line I am afraid).
But the script resets the W/S only, doesn't reset the Actions, Brushes, C.Shapes and Styles to the ones I have saved as defaults in my W/S.
I still need to find a way to say to Photoshop something like: "Select this set of Styles (name of Styles set), set it as default and replace the previous" and "Select this set of Actions (name of Actions set), bring it to the Actions Panel and check if there is already a copy of that set".
As I wrote earlier, the assets are already in the "Presets" folder of Photoshop, so they are loaded once the program starts, I need to bring them in front and make them active.
Thank you once again for your effort to help me!
Copy link to clipboard
Copied
Hum.........
I have functions that launch styles and brushes.
But I'm not sure I understand everything you want - poor French brains!
Copy link to clipboard
Copied
Probably it's my way of thinking that makes you confused. Let me re-explain.
I have a Panel, this Panel needs some assets in order to work properly (Brushes, Custom Shapes, Styles & Actions).
These assets are already installed inside the "Presets" folder of Adobe Photoshop.
When I open Photoshop, I click on the Panel to activate it and then I need to click a button on the Panel, which is connected with a script, to bring those assets as defaults in the Actions, Styles, Brushes & Custom Shapes Panels.
So I think I need a script that says: "Photoshop, find this set of actions (example "Panel Actions") which is already in your list and bring it inside the Actions Panel and please check if there is already there" (in case of a crash the user should re-press the button to bring all the assets).
The same should happen with Custom Shapes & Styles, but these must replace the previous sets or at least bring a dialogue to let the user replace or append the set.
I really appreciate your efforts!