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

Is there a way to clear or delete actions through scripting?

Contributor ,
May 13, 2015 May 13, 2015

Hello Everyone!

Menu Commands Outline Stroke

I'm trying to make a script that will clear and then reload actions to try to get around that bug. Thanks to quertyfly and moluapple I now know how to make actions through script so all I need to know if there is a way to clear actions through script.

Thanks Everyone!

TOPICS
Scripting
8.5K
Translate
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

correct answers 1 Correct answer

Guide , May 14, 2015 May 14, 2015

Woo Hoo....

feeling a bit stupid that I had not tried this.

But it works.

You don't even need to first unload each action

to remove a set...

app.unloadAction('Test Set','');

now to activate the file menu...

Translate
Adobe
Guide ,
May 13, 2015 May 13, 2015

this is a tricky one...

initial problem:

scripts can be added to an action so we can run via a keyboard shortcut,

BUT, on restart the scripts are not loaded back into the action.

added issue:

removing the action set and loading it again from a saved '.aia' file does not work.

To get this to work we first need to wake the illustrator script menu.(dumbfounded expression)

This is just a matter of opening the File menu. (I do this by pressing "ALT" then "f" then "ESC")

now the actions can be loaded and attached scripts will be linked in correctly.

What we Can do:

We can add an action set and actions to the action panel via a script.

We can load the above actions using a Startup script.

We can unload a script from the actions panel.

What we Can't do: ( or more to the point, What I Can't work out how to do:...)

I can't work out how to remove an action set.

When actions are added via a startup script, it does not register any linked scripts

I can't work out how to activate the file menu via a script.

Translate
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
Contributor ,
May 14, 2015 May 14, 2015

Thanks for your help, I definitely learned something.

I was ignorant on the real cause of the script actions not registering when you reloaded them. On my own trial and error I found a way that always worked, by opening a new file (through the menu), and then loading the actions. I thought by opening a file via script, then loading the actions, then closing the file it would solve the not registering issue. I now know that I was wrong, opening a file does nothing, like you said, all that matters is opening the file menu. I tested this by instead of going to file < new through the menu like I would always do, I hit control N for a new file instead, then I loaded my script actions, and none of them registered.

So crap, that is another issue I was not prepared for haha. So we are two steps away instead of one.

Translate
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 ,
May 14, 2015 May 14, 2015

I think that most can live with the showing File menu workaround for scripts in actions, as that's a fairly quick task only needed at AI startup. I guess this could be remedied via platform-specific scripts.

There's got to be a way via sendScriptMessage, but if there is, nobody knows the parameters, they are a mystery!

Translate
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 ,
May 14, 2015 May 14, 2015

What do we want?

-- To remove actions from the actions palette!

When do we want it?

-- Sooner than retirement!

Translate
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
Community Expert ,
May 14, 2015 May 14, 2015

Hahaha loud and clear...feature request?

Translate
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 ,
May 14, 2015 May 14, 2015

Okay, let's all just throw in stuff that does not work, and maybe through crowd-sourced trial & error, as most items get resolved here, there could emerge an answer. Or, hopefully someone in Adobe will see this thread and take pity.

So, I'll go first:

app.sendScriptMessage("AdobeActionPalette", "Delete Selection", '<selection="TEST2">');

// does not work, none of these work... but they do not trigger an error, so AdobeActionPalette or AdobeActionManager are definitely out there getting these incorrect messages

app.sendScriptMessage("AdobeActionPalette", "Delete", '<action="TEST2">');

app.sendScriptMessage("AdobeActionPalette", "Delete", '<actionSet="TEST2">');

app.sendScriptMessage("AdobeActionPalette", "Delete", '<action-set="TEST2">');

app.sendScriptMessage("AdobeActionPalette", "Remove", '<set="TEST2">');

app.sendScriptMessage("AdobeActionPalette", "Remove Selection", '<selection="TEST2">');

Translate
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
Guide ,
May 14, 2015 May 14, 2015

as a place to get started.

do we even know if sendScriptMessage can do anything with the ActionPalette?

if you know of an example that can achieve something then we would have somewhere to start.

Translate
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
Guide ,
May 14, 2015 May 14, 2015

Woo Hoo....

feeling a bit stupid that I had not tried this.

But it works.

You don't even need to first unload each action

to remove a set...

app.unloadAction('Test Set','');

now to activate the file menu...

Translate
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
Community Expert ,
May 14, 2015 May 14, 2015

...unfortunately, removing an Action leaves the Set behind, that leads us to add the Action into an existing set

Translate
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
Guide ,
May 14, 2015 May 14, 2015

the above removes the set.

Translate
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
Community Expert ,
May 14, 2015 May 14, 2015

Qwertyfly... wrote:

the above removes the set.

I see, it does work with an empty string, good find.

Translate
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
Guide ,
May 14, 2015 May 14, 2015

now I have hit a wall.

it seems that a startup script does not Just run at startup as I supposed...

it actually runs before every script you run.

grrrrr

that just does not make any sense to me.

does anyone have any ideas???

Translate
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
Guide ,
May 14, 2015 May 14, 2015

Ok so I think it should go in the "General Startup Scrips Folder".

but can't seem to get it to run from there.

not sure what i'm missing...

Translate
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
Guide ,
May 15, 2015 May 15, 2015

not perfect but here is the start.

save this script to your scripts folder. (DONT FORGET TO UPDATE THE 2 VARIABLES)

then running that will reload your actions and as you had to use the file menu to run it.

// Auto Reload Actions for persistant Linking to Scripts

//

//

//                  Qwertyfly

//                  Version 1

//                  15-05-15

//

//

// Name of the Action Set as it apears in the Action Panel

var set = 'MyActions';

// Location of your saved Actions.aia file

var aia = File('~/MyActions.aia');

//

//

try{

app.unloadAction(set,'');

}catch(e){}

app.loadAction(aia);

I have an idea on how to automate this but I have to get out of here.

so I'll post this for now.

I need to work out how to run a script at startup, just once, not every time another script is run.

Translate
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 ,
May 15, 2015 May 15, 2015
I need to work out how to run a script at startup, just once, not every time another script is run

I shall pay you back for your discovery with this:

if ($.engineName != "transient"){

//run start up script

}

Translate
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
Guide ,
May 15, 2015 May 15, 2015

‌tthanks Silly,

ill have a play with that

Translate
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
Guide ,
May 17, 2015 May 17, 2015

Thanks again Silly,

Here is a working version (for windows)

is not perfect, it relies on a sleep command, so if the program takes too long to load it will not work.

can a VBscripter enlighten me on how to wait for illustrator to finish.

and I need a Macster to get the applescript section finished as I don't have a mac.

I started nutting the basics out, but did not know accessing the file menu via keystrokes was so hit and miss on a mac.

and is the applescript extension really ".APPLESCRIPT"

I am so glad we we have ".pdf" and not ".ADOBESPORTABLEDOCUMENTFORMAT"

any improvements would be appreciated.

// Auto Reload Actions for persistant Linking to Scripts

//

//

//                  Qwertyfly

//                  Version 1

//                  18-05-15

//

//

//         Place this file in:  (this is an example and may not reflect your exact file structure)

//          Windows: C:\Program Files\Adobe\Adobe Illustrator CC 2014\Startup Scripts\

//          Mac OS: /Applications/Adobe Illustrator CC 2014/Startup Scripts/

//

//

//

if ($.engineName != "transient"){

// Name of the Action Set as it apears in the Action Panel

var set = 'MyActions';

// Location of your saved Actions.aia file

var aia = '~/MyActions.aia';

//

//

try{

    app.unloadAction(set,'');

}catch(e){}

    LoadActions(aia);

    //Test for Mac or PC

    // I'm sure there is a better way to do this....

    AppPath = String(app.path);

    test = AppPath.indexOf("Application");

    if(test == -1){

        ActivateFileMenu_Windows ();

    } else {

        ActivateFileMenu_Mac();

    }

}

function ActivateFileMenu_Windows(){

    var VB = [

        'Set appRef = CreateObject("Illustrator.Application")',

        'WScript.Sleep 3000', // there has to be a better way to wait for file menu to be active

        'Set WshShell = WScript.CreateObject("WScript.Shell")',

        'WshShell.SendKeys "%f"',

        'JS = "~/go.jsx"',

        'appRef.DoJavaScriptFile(JS)',

        'WshShell.SendKeys "{ESC}"'

        ].join('\n');

    var VBgo = new File('~/go.vbs');

    VBgo.open('w');

    VBgo.write(VB);

    VBgo.close();

    VBgo.execute();

}

function ActivateFileMenu_Mac(){

    var AS = [

        'tell application "Adobe Illustrator"',

        'delay 1',

        // Someone else will need to take over from here as I dont have a mac.

        'end tell'   

        ].join('\n');

    var ASgo = new File('~/go.APPLESCRIPT');

    ASgo.open('w');

    ASgo.write(AS);

    ASgo.close();

}

function LoadActions(aia){

    var JS = [

        'var aia = File("' + aia + '");',

        'app.loadAction(aia);'

        ].join('\n');

    var LoadAct = new File('~/go.jsx');

    LoadAct.open('w');

    LoadAct.write(JS);

    LoadAct.close();

}

Translate
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
Community Expert ,
May 17, 2015 May 17, 2015

I was testing this same approach, it seems the vbs script will load whenever illustrator has loaded. It worked everytime here, though I was trying with 5 seconds and I my script only had the loading of the Menu, I was planing on doing that only and run the Action Loading script manually.

One issue with CC is that if the Welcome Screen is on, then my script not always worked

Translate
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
Guide ,
May 17, 2015 May 17, 2015

I did not think of that as I turned my welcome screen of first time I saw it.

the other option was to ad the load actions part of the script in the standard script folder.

then use the vbscript to do the "alt f r loadActions Enter" or some such

at least then if it failed, all you need to do is manually run load actions.

I just thought this way there was just 1 file to put in the correct folder to get it up and running.

would also remove need for pause...

Translate
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
Contributor ,
May 18, 2015 May 18, 2015

Works great with CS6 on windows! I need to learn more about VB. Had to add a few seconds to the sleep command because I have a crappy computer and a lot of fonts, it takes a while for illustrator to open. Very cool!

Translate
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
Contributor ,
May 15, 2015 May 15, 2015

I'm working with CS6 and both app.unloadAction and app.loadAction work like a charm.


I was wondering, with CC, is it possible to have an action that runs a script that runs an action?

Or is that still a no no


Thanks for everyone's input! This is coming along strong. I wish I could help more but I have only been into programming for about a year so a lot of this stuff is over my head.

Translate
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 ,
May 15, 2015 May 15, 2015

Yes, what you said should work by all means.

Translate
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
Contributor ,
May 15, 2015 May 15, 2015

Nice, they must have fixed that. If I try to do that with CS6 it just crashes my Illustrator. So I just leave those scripts on my desktop instead. Ill hope we get CC eventually.

Translate
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 ,
May 15, 2015 May 15, 2015

Well, then, I didn't know it crashed- will need to do my own test on CC too.

Translate
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