How to easily publish scripts with an include and icons?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Timo Autiokari

How to easily publish scripts with an include and icons?

Post by Timo Autiokari »

I have now many scripts that I could make make available but they are using one include file and some icons. I like the icons because they immediately tell that the dialog is from a script.

So, I can flatten.js (by X) but what do I do with the icon? It would be so nice if a published script would be just a single file.

Also, it would be very neat if the flatten.js would only take the required portions of the include file instead of the whole file. Horrible amount of work in that I guess.

Timo Autiokari
xbytor

How to easily publish scripts with an include and icons?

Post by xbytor »

Timo Autiokari wrote:So, I can flatten.js (by X) but what do I do with the icon? It would be so nice if a published script would be just a single file.


It's not clear what you are using the icon for. If it is for something like an icon button or a ScriptUI image widget, there is a way around this.

I had a client that needed to bundle styles (.asl files) in their scripts.

In stdlib.js there is a set of functions for converting binary data to hex strings and hex to JS constants.

The approach is to write a utility script takes the file (.asl, .jpg, whatever), reads it into memory, translates it to hex string, then formats the hex string for use as a JS string constant. The result is something that looks like this:

Code: Select all// generated from xstyle.asl
var xstyle =
"00023842534C0003000000000000000100000230000000100000000100000000" +
  "00006E756C6C00000002000000004E6D2020544558540000000A00740065006D" +
  "0070005300740079006C006500000000000049646E7454455854000000250030" +
  "0064006300370036006100630061002D0034006200310039002D003100310064" +
  "0062002D0039003300310034002D006600380030003000360063006100350036" +
  "003900350038000000000010000000010000000000005374796C000000020000" +
  "000C646F63756D656E744D6F64654F626A630000000100000000000C646F6375" +
  "6D656E744D6F646500000000000000004C6566784F626A630000000100000000" +
  "00004C656678000000030000000053636C20556E7446235072634075B38E38E3" +
  "8E390000000E6D61737465724658537769746368626F6F6C0100000000467246" +
  "584F626A6300000001000000000000467246580000000700000000656E616262" +
  "6F6F6C01000000005374796C656E756D000000004653746C00000000496E7346" +
  "00000000506E7454656E756D000000004672466C0000000053436C7200000000" +
  "4D642020656E756D00000000426C6E4D000000004E726D6C000000004F706374" +
  "556E744623507263405900000000000000000000537A2020556E74462350786C" +
  "402E00000000000000000000436C72204F626A63000000010000000000005247" +
  "4243000000030000000052642020646F7562406FE00000000000000000004772" +
  "6E20646F7562406FE0000000000000000000426C2020646F7562406FE0000000" +
  "00000000";


Your script that generates this puts it in jsx file (e.g. xstyle.jsx). You include this script in your main application script. You also run Flatten so that you have everything in one script.

In that main application script, you have a function that will recreate that file (xstyle.asl) (based on this string) when the script is run. You can either create the file once and put it someplace the scripts checks on startup, or you create the file in a temp directory every time the script is run.

I started writing an xtools/xlib script called EmbeddedFile that does all of this. My motivation was to embed styles but you could also embed icons. The technique that I describe above is what I planned on doing.

Also, it would be very neat if the flatten.js would only take the required portions of the include file instead of the whole file. Horrible amount of work in that I guess.


I believe that Andrew once had a script that would do something like this. I never really saw the need. It doesn't bother me to send scripts out with >>10KLOC.

-X