Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Illustrator]Create, load and execute action all by JS only
// CS6 only
var set = 'Script Action', // 动作集名称
action = 'PastePDF', // 动作名称
menuEn = 'paste', // 菜单英文
menuZh = '粘贴', // 菜单中文
actionStr = ['/version 3',
'/name [ ' + set.length,
ascii2Hex(set),
']',
'/isOpen 0',
'/actionCount 1',
'/action-1 {',
'/name [ ' + action.length,
ascii2Hex(action),
']',
'/keyIndex 0',
'/colorIndex 0',
'/isOpen 1',
'/eventCount 1',
'/event-1 {',
'/useRulersIn1stQuadrant 0',
'/internalName (adobe_commandManager)',
'/localizedName [ 15',
'e8aebfe997aee88f9ce58d95e9a1b9',
']',
'/isOpen 0',
'/isOn 1',
'/hasDialog 0',
'/parameterCount 3',
'/parameter-1 {',
'/key 1769238125',
'/showInPalette -1',
'/type (ustring)',
'/value [ ' + menuEn.length,
ascii2Hex(menuEn),
']',
'}',
'/parameter-2 {',
'/key 1818455661',
'/showInPalette -1',
'/type (ustring)',
'/value [ ' + menuZh.length * 3,
GBK2Hex(menuZh),
']',
'}',
'/parameter-3 {',
'/key 1668114788',
'/showInPalette -1',
'/type (integer)',
'/value 1885434740',
'}',
'}',
'}'].join('\n');
createAction(actionStr, set);
app.doScript(action, set);
app.unloadAction(set,'');
function createAction (str, set) {
var f = File(set + '.aia');
f.open('w');
f.write(str);
f.close();
app.loadAction(f);
f.remove();
}
function ascii2Hex (hex) {
return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})
}
function GBK2Hex (str/*中文字符*/) {
var f = File('hex.txt'), hex;
f.encoding = 'UTF8';
f.open('w'), f.write(str), f.close();
f.encoding = 'BINARY';
f.open('r');
hex = f.read().toSource().replace(/(?:\(new String\("|"\)\)|\\u00)/g, '');
f.close(), f.remove();
return hex
}
@J-RaulPerez

This comment has been minimized.

Copy link

@J-RaulPerez J-RaulPerez commented Sep 26, 2019

Hi.
I like a lot this idea to implemnt instructions that Illustrator Javascript can do.
My question is if it is possible to do with this method, to unembed a rasterized item and save it intact (with every imformation of its colors, including Spot Colors) in psd format with a given name.

I can't find the solution to unembed a rasterized item to PSD with Spot Colors Channels (not only cmyk channels).

I can see that you are very intelligent and you have lot of knowledges. If you can help me to resolve this question I will be eternally grateful to You.

Thanks in advance.

Raúl Pérez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment