• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JS: Deleting Actions using Wildcard Variables.

New Here ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

I am working on a JS snippet that will delete action sets from the action pallete. The code will be ran from an AppleScript.

I used ScriptListener to get the basic code:

var id1 = charIDToTypeID( "Dlt " );
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id3 = charIDToTypeID( "ASet" );
ref1.putName( id3, "Profile Actions_V4" ); //Action set being deleted
desc1.putReference( id2, ref1 );
executeAction( id1, desc1, DialogModes.NO );


It works, but I need to make the action set name a variable with a wildcard. So the string Profile Actions_V4 should be something like Profile Actions_V*. The number after the V is a version number, and the goal is to delete any possible versions the user has loaded into their actions palette.

I'm not into JS at all, so I'm thinking my problem may have to do with basic syntax, so I looked into regular expressions. Photoshop gave me this error:

Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The object set RegExp is not currently available.
Line: 10
-> executeAction( id33, desc7, DialogModes.NO );


Thought? Thanks.

Carl.
TOPICS
Actions and scripting

Views

618

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
New Here ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

I'm using CS3 on Mac OS10.4.9.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

Hi Carl, you need to get a list of all your Actions set and test for the ones you want to delete.
This should delete all Action Sets with Profile Actions_V





unLoadAction( GetActionSetInfo());



function GetActionSetInfo() {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

var i = 1;

var sets = [];

while (true) {

var ref = new ActionReference();

ref.putIndex(cTID("ASet"), i);

var desc;

var lvl = $.level;

$.level = 0;

try {

desc = executeActionGet(ref);

} catch (e) {

break; // all done

} finally {

$.level = lvl;

}

if (desc.hasKey(cTID("Nm "))) {

var set = {};

set.index = i;

set.name = desc.getString(cTID("Nm "));

set.toString = function() { return this.name; };

set.count = desc.getInteger(cTID("NmbC"));

set.actions = [];

for (var j = 1; j <= set.count; j++) {

var ref = new ActionReference();

ref.putIndex(cTID('Actn'), j);

ref.putIndex(cTID('ASet'), set.index);

var adesc = executeActionGet(ref);

var actName = adesc.getString(cTID('Nm '));

set.actions.push(actName);

}

sets.push(set);

}

i++;

}

return sets;

};

function unLoadAction(aSets){

for ( var c = 0; c < aSets.length; c++ ) {

if(aSets.toString().substr(0,17) == 'Profile Actions_V'){

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putName( charIDToTypeID( "ASet" ), decodeURI(aSets) );

desc.putReference( charIDToTypeID( "null" ), ref );

executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );

}

}

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

Here another version using regex, you can pass in the names of the sets you want to delete Carl.





unLoadAction( GetActionSetInfo(),"Profile Actions_V");



function GetActionSetInfo() {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

var i = 1;

var sets = [];

while (true) {

var ref = new ActionReference();

ref.putIndex(cTID("ASet"), i);

var desc;

var lvl = $.level;

$.level = 0;

try {

desc = executeActionGet(ref);

} catch (e) {

break;

} finally {

$.level = lvl;

}

if (desc.hasKey(cTID("Nm "))) {

var set = {};

set.index = i;

set.name = desc.getString(cTID("Nm "));

set.toString = function() { return this.name; };

set.count = desc.getInteger(cTID("NmbC"));

set.actions = [];

for (var j = 1; j <= set.count; j++) {

var ref = new ActionReference();

ref.putIndex(cTID('Actn'), j);

ref.putIndex(cTID('ASet'), set.index);

var adesc = executeActionGet(ref);

var actName = adesc.getString(cTID('Nm '));

set.actions.push(actName);

}

sets.push(set);

}

i++;

}

return sets;

};

function unLoadAction(aSets,ActionName){

for ( var c = 0; c < aSets.length; c++ ) {

if(aSets.toString().match (new RegExp (ActionName, 'gi'))) {

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putName( charIDToTypeID( "ASet" ), decodeURI(aSets) );

desc.putReference( charIDToTypeID( "null" ), ref );

executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );

}

}

};



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

LATEST
Here's my variant. I've added a call to 'confirm' so that you don't
inadvertently wipe out your action's palette.

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines