Creating a dynamic action to use with app.doScript() method.

Adobe Community Professional ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

Since building dynamic actions is a topic unto itself, we often search for a reference thread to show somebody how to do this - and we often do so while trying to discuss work which is already involved and has nothing to do with actions or loading and playing them. Therefore I'm creating this thread to show an example and I'll paste the url to it when such questions arise.

Sometimes in Illustrator scripting we need to accomplish tasks which (sometimes counterintuitively) do not have scripting access via the DOM.

Fortunately since Illustrator CS6, they gave us the ability to play an action from a script with the app.doScript() command - which is not at all the same as Indesign's function of the same name. This one lets you play an action that exists inside the Actions panel. Immediately this may seem disappointing as users cannot be counted on to have specific actions at any given time.

However, they also gave the ability to load and remove actions from .aia action files. Your .aia file just needs to be somewhere and app.loadAction() can read it right into the Actions panel. Same with app.unloadAction(setName, actionName) - where (thanks to qwertyfly) using (setName, "") an empty string argument for the action name will remove the entire set. And when you try to remove an action that does not exist, well, it throws an error - which is how you can check for making absolutely sure that an action set is completely removed.

This may seem like a lot of work - to write a file, read it, play it and then discard it, often to do something that you'd think scripting should do in the first place.

Sometimes the action alone is enough to satisfy an objective - such as changing the document color mode. Other times it is necessary to alter actions in order to get use out of them - such as when you try to create a routine for saving a high-resolution "Export" JPG that is different in output and options form the "Save for Web" JPG. You may want to change some of the parameters such as resolution or the actual destination of the file.

Here is how you can do this.

First, record your action as you would normally: record a new set with a new action, call them what you need and then in the Actions flyout menu, save out a .aia file where you can find it. You can open the file in a text editor and read the contents - they are lines of special Actions 'code' which contains some cryptic text.

There are lines which look like a bunch of gibberish characters, they are hex-encoded strings for some parameter item which are strings, and they contain above them a number to signify the amount of characters inside the encoded string. (this is important later because this number also needs to be set properly when you put your own value in there) Other parameter items are simple numbers, but their keys are still obscured.

The truth is, while the string parameters are hexadecimal-encoded, the keys are both hexadecimal and decimal encoded! So if you wanted to know the special 4-letter keys, you'll have to run those through two decoder routines.

Next, you will need to put this entire string into your script and use some string-replacement or string-building to put your own data in those places of the action string where they matter. For example, putting your own file path into a save action.

And, after that you need to write a procedure for writing this new altered string to the file system and loading it into your Actions panel. Mind you, to leave things "as they were" you would need to remove the .aia file and the action that you have loaded.

Let's try with the save-a-jpeg workaround!

Here is the .aia string which is recorded from an Export JPEG action.

Screen Shot 2017-02-10 at 3.04.33 PM.png

/version 3

/name [ 8

  5475746f7269616c

]

/isOpen 1

/actionCount 1

/action-1 {

  /name [ 11

  4578706f7274204a504547

  ]

  /keyIndex 0

  /colorIndex 0

  /isOpen 1

  /eventCount 1

  /event-1 {

  /useRulersIn1stQuadrant 0

  /internalName (adobe_exportDocument)

  /localizedName [ 9

  4578706f7274204173

  ]

  /isOpen 1

  /isOn 1

  /hasDialog 1

  /showDialog 0

  /parameterCount 7

  /parameter-1 {

  /key 1885434477

  /showInPalette 0

  /type (raw)

  /value < 100

  0a00000001000000030000000200000000002c01020000000000000001000000

  69006d006100670065006d006100700000006f00630000000000000000000000

  0000000000000000000000000000000000000000000000000000000000000000

  00000100

  >

  /size 100

  }

  /parameter-2 {

  /key 1851878757

  /showInPalette 4294967295

  /type (ustring)

  /value [ 25

  2f55736572732f566173696c7948616c6c2f4465736b746f70

  ]

  }

  /parameter-3 {

  /key 1718775156

  /showInPalette 4294967295

  /type (ustring)

  /value [ 16

  4a5045472066696c6520666f726d6174

  ]

  }

  /parameter-4 {

  /key 1702392942

  /showInPalette 4294967295

  /type (ustring)

  /value [ 12

  6a70672c6a70652c6a706567

  ]

  }

  /parameter-5 {

  /key 1936548194

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-6 {

  /key 1935764588

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-7 {

  /key 1936875886

  /showInPalette 4294967295

  /type (ustring)

  /value [ 1

  32

  ]

  }

  }

}

We can see many parameters and their various cryptic blocks, but what you want to do is decode as many /type (ustring) elements as possible to get a sense of what the action is doing. At this website, you can do this fairly easily although tediously: Convert Hexadecimal To String Online

For example: "4a5045472066696c6520666f726d6174" turns into "JPEG file format".

In this action example, I am not worried about changing the other parameters dynamically - I'm assuming the settings used in my action are suitable for my purposes such as resolution being 300 for all time. The part I'd like to change is my file path so that my JPEG goes to the right place.

/value [ 25
2f55736572732f566173696c7948616c6c2f4465736b746f70
]

This line yields: "/Users/VasilyHall/Desktop"

So this is the line I'll need to replace.

Before anything else - here is how I'd embed the action string with ease. Using a text editor like Sublime text which lets you put many cursors down at one time, I can paste the action string in and find every nextline character. Then it's easy to highlight each line and put quotes around it as well as a comma in the end, or plusses - depending if you want to store the string as an array or a plain string in the script.

Screen Shot 2017-02-10 at 3.16.48 PM.png

I find the plusses a little cluttering so I opt to use this format:
var actionString = [     "string",

     "string"

].join("\n");

So my dynamic portion of the string which will be used with string replacement would look like this:

"  /value [ {{number_of_characters}}",

"  {{hex_encoded_path}}",

"  ]",

When the action is ready to be dispatched, a string replacement would look like this:

var myNewPath = Folder.myDocuments.toString() + "/Destination";

var myNewPathEncoded = hexEncode(myNewPath); // find a hex encode function via google
var thisActionString = actionString.replace("{{hex_encoded_path}}", myNewPathEncoded).replace("{{number_of_characters}}", myNewPath.length);

Now it's time to write the file.

var f = File(actionFileLocation);

f.open('w');

f.write(thisActionString);

f.close();

And now it's time to load the action.

app.loadAction(actionFileLocation);

Now we can play the action.

app.doScript("Export JPEG", "Tutorial");

This should save your jpeg, and as of this writing, this is the only way to get the JPEG export which isn't the Save-for-Web variety.

But, let us not forget the cleanup.

Remove the .aia file:

f.remove();

Remove the single-use dynamic action:

app.unloadAction("Tutorial", "");

There you have it: building dynamic actions to do simple and non-simple things, which regular scripting just can't do.

TOPICS
Scripting

Views

7.7K

Likes

translate

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 Community Professional ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

Despite google translate repeatedly telling me otherwise, I'm becoming more and more convinced that 'Vasily' is Russian for 'Wizard'.

This is extremely helpful. Thanks a ton for taking the time to put this together. It's going to help a ton of people, I'm sure.

Likes

translate

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 Community Professional ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

No problem, I hope it helps others too and it helps me when I can point to this thread.

Likes

translate

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 Community Professional ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

Oh yes, and my apologies for incorrectly implying that the export JPEG settings are actually recorded into an action. This is not the case; the export settings are actually kept in the Prefs file and can be manipulated via this syntax: app.preferences.setRealPreference("plugin/JPEGFormat/DPI", 450);

Okay, correction - the resolution settings get baked into the action when it's recorded! And what's more, they change your preferences when they are ran. You can have set the preferences with script to have resolution of Jpegs to 200 and if you play an action which exported them at 300, the prefs get updated to the 300.

I am suspecting this kind of info is hidden inside this block in the action text:

/key 1885434477// parm
/showInPalette 0
/type (raw)
/value < 96
e0d1955c010000000000000000000000e0810699010000000300000000005e01
02000000000000000200000000000000c0cf9c17010000000200000000000000
01000000000000000000000000000000b0f17738010000000007975c01000000
>

Anyone know how to decode or encode it?

Likes

translate

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 Community Professional ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

I recorded and analyzed a Tiff of a different resolution and the difference was this bit: "5e01"

Likes

translate

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
Enthusiast ,
Apr 08, 2017 Apr 08, 2017

Copy link to clipboard

Copied

Hi, check this:

5e01: 0x5e = 94, 0x01 = 1, 94 +1 + 255 * 1 = 350

More tests:

2c01: 44 + 1 + 255 * 1 = 300

c800: 200 + 0 + 255 * 0 = 200

5802: 88 + 2 + 255 * 2 = 600

Likes

translate

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 Community Professional ,
Apr 08, 2017 Apr 08, 2017

Copy link to clipboard

Copied

Wow most excellent work! I would have never figured this out. This is just like one of those pictures where you have to find a pattern in the numbers - but in real life! I am going to make an image like that.

So, it follows that the following function should work to change this bit of string. Maybe there's a way to get the information on all of the parameters in this raw data string body, but it would take tedious work to map all of these out, right?

#target illustrator

function test(){

  var helper = {

    hexToString : function (hex) {

        var str = '';

        for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));

        return str;

    },

    decToHex : function (dec){

      return parseInt(dec).toString(16);

    },

    decToHexToString : function (dec){

      return this.hexToString(this.decToHex(dec));

    }

  };

  function getResolutionString(resNum){

  var remainder = resNum % 255;

  if(remainder == 0){

  remainder = 255;

  }

  var multiplier = (resNum - remainder) / 255;

  return helper.decToHex(Math.abs(remainder - multiplier)).replace("0x", "") + "0" + multiplier.toString();

  };

  var str = getResolutionString(300);

  alert(str);//###

};

test();

Likes

translate

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
Enthusiast ,
Apr 10, 2017 Apr 10, 2017

Copy link to clipboard

Copied

Well, not so much works as thought, it turns out the last line is always the same, and other values are much more simple than dpi: 01,02,03 or 00,01.

d0037405000000000000000000000000c0660f1c00000000{antialias::start:49, length:2, value:[01,02,03]}0000000000{dpi::start:61, length:4, value:encoded hex }

{color_type::start:65, length:2, value:[01,02,03]}000000{lzw::start:73, length:2, value:[00,01]}00000002000000000000008028560d00000000{icc::start:113, length:2, value:[00,01]}00000000000000

01000000000000000000000000000000a0b5791d0000000030b7791d00000000

I noticed that the data are different from your sample, may be it's relative to version and locale, I just don't care about it.

Likes

translate

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 Community Professional ,
Feb 19, 2018 Feb 19, 2018

Copy link to clipboard

Copied

Two corrections on this:

  1. Using an Action is not the only way to save a high-res JPEG, you can also use the imageCapture function with the right preferences or file-name endings.
  2. Extendscript has a special sweet feature (kind of in the same league as being able to write <xmlTags></xmlTags> inside an extendscript), the ability to use triple quotes (''') or (""") to set apart entire blocks of text as a string, regardless of nextlines and nested quotes.

I couldn't help myself, here's the XML example:

#target illustrator

function test(){

var stuff = <root>

        <innerTag>HELLO!</innerTag>

    </root>;

    alert(stuff.innerTag); // HELLO!

};

test();

And here's the triple-quote example:

#target illustrator

function test(){

    var stuff = """

        The cow jumped over-

        the moon. "Isn't that wonderful",

        -- said the artifical intelligence, right before it took everyone'"s''"'"'"' job's's's's's""''

    """;

    alert(stuff);

};

test();

Screen Shot 2018-02-19 at 12.17.04 PM.png

Likes

translate

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 Community Professional ,
Mar 22, 2018 Mar 22, 2018

Copy link to clipboard

Copied

Awesome bug alert! A 'magic undo' bug is discovered.

But first, a very important notice first: do not use a script that writes in and plays actions, from inside an Action in the first place. This causes Illustrator to go unresponsive.

Here is my exciting story: using Mac, AI 22.1, I set out to practice this very technique to save a copy in PDF format on a document which my script would edit first, doing such things as removing layers, duplicating and outlining text, etc.

Using ESTK to launch the script which included using the action with the load-play-remove methodology, the script worked as expected.

However, when using File > Other Scripts, the script worked just fine except all the items it edited in the document instantly reverted at the end of the script! It just jumped back to the state of being, before my script's editing came into play. Basically, all the layers it was meant to delete permanently, were deleted in a flash and just as quickly re-appeared, with all art back in place. I even checked my action to see if I did not accidentally add an "undo" there. It appeared to do the same thing as if I was pushing Cmd Z at the end of the script run!

The solution for me was to put in an app.redraw() command before my action played: now the document state became fixed and did not instantly and magically revert.

While I pondered on the usefulness of this 'feature', in the end my thoughts are to avoid it if possible and to treat it as an anomaly and not the standard behavior to be relied upon.

Likes

translate

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
Engaged ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Just a thought that comes to my mind after enjoying this must-read article above:

You can't call a script through an action, because it will only work once and then be forgotten by AI.

You can't assign a hotkey to a script.

But:

You can do a script that creates a dynamic action (as mentioned above).

You can assign a hotkey to that dynamic action.

You can use a script as startup item to run when AI is started.

So my idea would be to create a dynamic action with a hotkey assigned and use it as a startup script. The result would be an action that could call the script more than once and by use of a hotkey.

I would appreciate any suggestions about that from the pro's around here.

Likes

translate

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 Community Professional ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

I think that's a great idea and a good use of this functionality. I do believe that the newer versions of AI have solved the issue of scripts in the actions panel not being persistent, however, your solution makes it much more portable because the action wouldn't have to exist on anybody's local machine. you'd just need access to the script itself so you can copy it into the applications folder.

For additional administrative control (assuming you were sharing this with coworkers, subordinates or clients, instead of just using it for yourself) you could create a generic "action_creator.jsx" that accessed an outside text file that contained the action text. That way you could make updates to the action without any need for people to re-install the script in their Startup Scripts folder.

Kudos

Likes

translate

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
Most Valuable Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

q3player wrote:

"You can't call a script through an action, because it will only work once and then be forgotten by AI."

In CC 2018: Yes we can

Likes

translate

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 Community Professional ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

To hotkey scripts it's going to reach into the realm of OS automation, and with AutoHotkey or Snap.app on Mac you can hotkey all kinds of stuff.

The issue as william points out, has been fixed for persisting the action to hotkeys in the latest versions.

As for maintaining a central Actions repository - you can simply have your .aia file that users can load into their Actions panel.

This can be automatically done via startup script.

The actions can also be updated at any time by re-loading that .aia file.

Likes

translate

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 Community Professional ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

I beleive what q3player is saying is that you can assign a hotkey to the action, and the action calls the script. so this would actually give you easy access to script hotkeys, as long as your hotkey is f2, f3, ... with an optional cmd/ctrl and/or option/alt modifier.

Not a particularly robust way of using hotkeys, but it's a step in the right direction i think.

Likes

translate

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
Engaged ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

*sigh*

still forced to work with cs6

... and if you hit the like button on this post it's like salt in an open wound 😉

Likes

translate

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 Community Professional ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

So, in this case you can do an action-creator script, or something like I've done in the past - which is a script that you have to go to File > Scripts to play, but it would re-load a pre-determined and pre-made Action file that would have been made with the script menu items and shortcut keys.

However all this is just too much junk, when you might as well do Snap.app or Keyboard Maestro or Automator Services on a Mac or AutoHotKey on Winows. With those there's a little figuring out, but I'd venture to say, not as much as what we're talking about even. Plus, with those once you can hotstring some application or action for Illustrator, it's done the exact same way you'd do that for any other app - which makes me want to just point to those solutions as it's something that you can use for all time in all things!

Likes

translate

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 Community Professional ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

Note: I discovered something new today - I was practicing putting a regular script into the script folder in the Ai app folder so I could run it from the Actions panel via shortcut key to try our methods here.

I found out that in CC2018 at least, while a script can be invoked via the File > Scripts menu and run without the application having to have a document open, doing so from the Actions panel will result in the "Object not available" error.

So we can see they made it so for some reason.

But it can be worked around by putting a file-open command into an action and then running the script and then closing the opened file with the script as the first or last step - depending on what is being done.

Likes

translate

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 Community Professional ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

so even if line 1 of the script you were calling from your action was "app.documents.add();" you'd get an error with running the action?

Likes

translate

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 Community Professional ,
Apr 24, 2018 Apr 24, 2018

Copy link to clipboard

Copied

That's right - just tried that. It's no script at all - and this is on my work's Mac High Sierra, CC2018 Ai.

Likes

translate

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
Community Beginner ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi guys,

First post here so please go easy. I've been using these boards for almost a year and have benefitted greatly from advice and script samples to greatly improve day-to-day menial studio tasks, so firstly thank you all very much for the (unknowing) help.

I've been attempting to use this dynamic action. We've managed to write the dynamic action to a location as described, and the new file path hex encode is working, but the issue I'm having is when Illustrator attempts to write the action file. I get the following errors:

Screen Shot 2019-07-23 at 08.51.20.pngScreen Shot 2019-07-23 at 08.54.04.png

We're running AI 23.0.4 on High Sierra 10.13.6. My script is following. Hopefully someone may have a suggestion, although this is quite an old post. Thanks in advance.

var scr=  ["/version 3",

"/name [ 17",

" 504e47204578706f72742044657369676e",

"]",

"/isOpen 1",

"/actionCount 1",

"/action-1 {",

" /name [ 8",

" 4465636b20504e47",

" ]",

" /keyIndex 0",

" /colorIndex 0",

" /isOpen 1",

" /eventCount 1",

" /event-1 {",

" /useRulersIn1stQuadrant 0",

" /internalName (adobe_SaveForWeb)",

" /localizedName [ 12",

" 5361766520666f7220576562",

" ]",

" /isOpen 1",

" /isOn 1",

" /hasDialog 1",

" /showDialog 1",

" /parameterCount 11",

" /parameter-1 {",

" /key 1181578272",

" /showInPalette 4294967295",

" /type (enumerated)",

" /name [ 6",

" 504e472d3234",

" ]",

" /value 1347301940",

" }",

" /parameter-2 {",

" /key 1231975538",

" /showInPalette 4294967295",

" /type (boolean)",

" /value 0",

" }",

" /parameter-3 {",

" /key 1416785523",

" /showInPalette 4294967295",

" /type (boolean)",

" /value 1",

" }",

" /parameter-4 {",

" /key 1299477536",

" /showInPalette 4294967295",

" /type (boolean)",

" /value 1",

" }",

" /parameter-5 {",

" /key 1299477586",

" /showInPalette 4294967295",

" /type (integer)",

" /value 255",

" }",

" /parameter-6 {",

" /key 1299477575",

" /showInPalette 4294967295",

" /type (integer)",

" /value 255",

" }",

" /parameter-7 {",

" /key 1299477570",

" /showInPalette 4294967295",

" /type (integer)",

" /value 255",

" }",

" /parameter-8 {",

" /key 1097757761",

" /showInPalette 4294967295",

" /type (ustring)",

" /value [ 14",

" 54797065204f7074696d697a6564",

" ]",

" }",

" /parameter-9 {",

" /key 1131180097",

" /showInPalette 4294967295",

" /type (boolean)",

" /value 1",

" }",

" /parameter-10 {",

" /key 1399608180",

" /showInPalette 0",

" /type (raw)",

" /value < 1478",

" 0000000300000001000000000000000700000003010000000000000000000000",

" 0000010100000050000000010000006400000000000000000000000000000002",

" 00000000ffffffff0000000004ffffffff00000000ffffffff00000000ffffff",

" ff00000000ffffffff0000000000000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000",

" 00ff000000ff000000ff000000ff000000000000000000000000000001480000",

" 00100000000100000000000e54617267657453657474696e6773000000080000",

" 00004d7474434f626a630000000100000000000a4e6174697665517561640000",

" 000300000000426c20206c6f6e67000000ff0000000047726e206c6f6e670000",

" 00ff00000000526420206c6f6e67000000ff0000000054726e73626f6f6c0100",

" 00000b6164644d65746164617461626f6f6c010000000a66696c65466f726d61",

" 74656e756d0000000a46696c65466f726d617400000005504e4732340000000a",

" 696e7465726c61636564626f6f6c000000000c6e6f4d61747465436f6c6f7262",

" 6f6f6c000000001b7472616e73706172656e6379446974686572416c676f7269",

" 74686d656e756d0000000f446974686572416c676f726974686d000000004e6f",

" 6e65000000187472616e73706172656e6379446974686572416d6f756e746c6f",

" 6e6700000064",

" >",

" /size 1478",

" }",

" /parameter-11 {",

" /key 1231953952",

" /showInPalette 4294967295",

" /type (ustring)",

" /value [ {{number_of_characters}}",

" {{hex_encoded_path}}",

" ]",

" }",

" }",

"}"];

// The active document 

var doc = app.activeDocument; 

// The path of the original document 

var originalDocPath = doc.path; 

// The name of the original document 

var originalDocName = doc.name; 

// An array of all the layers in the active document 

var allLayers = doc.layers; 

// Get just the file name. Ignore the file extension .pdf and .ai 

originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")

var full = scr.join("\n");

var newpath = hexEncode(originalDocPath + "/" + originalDocName + ".png");

var thisActionString = full.replace("{{hex_encoded_path}}",newpath).replace("{{number_of_characters}}",newpath.length);

// function to hex encode the file path

function hexEncode(str) {

  var hex = '';

    for(var i=0;i<str.length;i++) {

        hex += ''+str.charCodeAt(i).toString(16);

    }

    return hex;

}

var actionFileLocation = "/Users/simonrutland/Desktop/PNG_Export_Design.aia";

// Now it's time to write the file.

var f = File(actionFileLocation);

f.open('w');

f.write(thisActionString);

f.close();

$.sleep( 5000 ); /*Milliseconds*/

// And now it's time to load the action.

var scriptFile = File(actionFileLocation);

app.loadAction(scriptFile);

// Now we can play the action.

app.doScript("Deck PNG", "PNG Export Design");

// alert(thisActionString);

Likes

translate

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 Community Professional ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

It might be worth creating a new post for this and then just referencing or linking Silly-V's post here. Giving it a separate post will help give you more exposure as well as helping to keep the forum organized and easy for others to navigate and find answers.

but in the mean time, I tested your your action, and I can't get it to load as an action at all. I'm suspicious of parameter-10. the hex code converts to complete gibberish.. even by adobe actions standards.

       P d ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ H   TargetSettings MttCObjc

NativeQuad Bl  longÿGrn longÿRd  longÿTrnsbool  addMetadatabool

fileFormatenum

FileFormat PNG24

interlacedbool noMatteColorbool transparencyDitherAlgorithmenum DitherAlgorithmNone transparencyDitherAmountlongd

When you make your new post.. Include, if you can, a copy of the action saved directly from illustrator (before you edited it) and a copy of your edited action. It might help to see what edits were made in terms of finding the bug.

Likes

translate

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
Community Beginner ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Thanks William. New post generated here: Dynamic actions with app.doScript() method

Likes

translate

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
New Here ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Hello,

I've been a regular visiter of this thread for a while now because I've need a way to create a dynamic Illustrator action for exporting JPEG's from Illustrator. Over the past year, I've put together a script that works great for me (thanks to all the hard work y'all have done before) and I wanted to share back. Maybe it can help someone else. 🙂

 

I all my code, documentation, and screenshots on public github repository: github.com/nathandietz/ExportDocAsJPEG.

 

Cheers!

 

Likes

translate

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 Community Professional ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Great job!

This block is super-helpful, if I have to use the export settings in the future, I know where to look for the example, thanks!

        '/value < 100 '       +   // Unknown
           imagQual + compMeth + numScans + aliasing + imageRes + colorMdl + mapStyle + mapStyle   +
          "69006d00   61006700   65006d00   61007000   00000000   00000000   00000000   00000000"  +
          "00000000   00000000   00000000   00000000   00000000   00000000   00000000   00000000"  +
           iccProfl           +
        '>' 

Likes

translate

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