AM Code Replacement

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: xbytor, DavideBarranca, Paul MR

Post Reply
User avatar
Posts: 189
Joined: Mon Jul 25, 2016 12:36 pm

AM Code Replacement

Post by Kukurykus » Mon Dec 12, 2016 5:13 am

I'd like to share with other scripters my new very useful script. It's a ScriptListener converter. In the result you get last made writible action did in Phosohop in much better and shorter shape. It let begginers understand it faster while pro developers change it for their needs than that was with 'machine' looking original SL code.


- there are 2 files in the .rar file: AM Code Replacement and AC.exe (plus just in case AC.ahk)
- put both files in the same folder, then launch Photoshop
- if you don't have any code recorded to ScriptListener.log on your Desktop, do anything can be written to
- run the script:
* in PS it uses AHK script to hihglight & copy code and press enter, so you can simply press ctrl v in any editor you use
* in Extendscript the text will be highlighted by a script but, AHK script won't be ran, so you must copy a code yourself

I created it in Photoshop 5.1 with Windows 10, but I think it should work with PS 6 and probably next versions too
I tested it so far with for ex. opening new document, creating text in text layer, adding effects, and Puppet Warp
If it won't work for you or if converted result ran again for ex. from Extendscript doesn't give the same result as PS let me know.
Possibly later I'll describe line after line what it exactly do before it reach final result.

An update to instructions:

First update was for suggestion of Jaroslav Bereza, who wanted chars were displayed as strings.

Now the second update is for Javier Archoe. Noone needs anymore be Windows user to copy content of result to clipboard automaticly by script. I was using AHK script to this, but now it's possible it will happen irrespectively beeing on Mac or Pc.

Another part of this update was fixing empty strings which were effect of most filters conversion from chars to strings. I simply restricted such changes if a script detected a result will be an empty string. So what can't be converted it will stay as original char. For example I checked all Artistic, Blur filters and single Liquify. I found these charIDToTypeID "Avrg", "BeIn", "BeNu", "BeS6", "BkDi", "BkDp", "BkDs", "BkIb", "BkIc", "BkIr", "BkIs", "BkNa", "BkNm", "BkNt", "BkSb", "BkSt", "Bokh", "BtDi", "BtIs", "BtNt", "GEfc", "GEfk", "GEft", "LqFy", "VnPt" dont' have equivalent stringIDToTypeID. There are probably more of them but fortunately that wasn't needed search for them all to make script working properly if it finds their "buddies".

I found also that script brekes with Lens Correction in filters section. I'm not sure I want to fix it. It seems a code partially looked like taken from XML, while I didn't designed a script to find its characters. It's only single case so probably I won't use even try...catch statement to fix it.

Code: Select all

function rw(v1, v2, v3) {, v1 < 'w' ? v3 = : v2.write(v3), v2.close(); return v3}

(win = new Window('palette' )).add('statictext {text: "Please wait to end of this process..."}'),

c = rw('r', File('~/Desktop/ScriptingListenerJS.log')).replace(/(.*\n(.*\n)+|^)([\/ =]+\n)+(.*(\n.*)+)\n\n/, '$4')

r = {a: ["'(^|;\\n) *(var )?'", '\r'], b: ["'\\\\( '", '('], c: ["' \\)'", ')'], d: ["'\"'", '\''], e: ["'ref'", 'REF'],
f: ["'desc'", 'DSC'], g: ["'list'", 'LST'], h: ["'string'", 's'], i: ["'char'", 'c'], j: ["'IDToTypeID'", 'TT']}
eval(l ="for(i in r) c = c.replace(eval('RegExp(' + r[i][0] + ',\"g\")'), r[i][1])");

for(i = 0, ARR = eval(arr = '[r.e[1], r.f[1], r.g[1]]'); i < (ARR).length; i++) {
if (!i) arr = eval(arr.replace(/1/g, '0')); arr[i] = ARR[i].toLowerCase(), n = 1
while(num = c.match(RegExp(ARR[i] + '\\d+'))) c = c.replace(RegExp(num, 'g'), eval(tLC = "arr[i]") + n), n++
if (num && !RegExp((onl = eval(tLC)) + 2).test(c)) c = c.replace(RegExp(onl + 1, 'g'), onl)

while(lne = c.match(/(\w+) = ((s|c)TT\('#?[\w ]*'\))/)) {
if ((Ps = /P.*p/.test( && lne[3] == 'c') {
l2 = lne[2], lne[2] = "sTT('" + eval(lne[2].replace(/cTT(.*)/, 'typeIDToStringID(charIDToTypeID$1)')) + "')"
if (/''/.test(lne[2])) lne[2] = l2
eval((slh = "c = c.replace(RegExp(lne[0].replace(/(?=\\()/, '\\\\').replace(/(?=\\))/, '\\\\')), '')")
+ ".replace(RegExp(lne[1] + '(?=,|\\\\))' + '\\\\b'), lne[2])")

for(i = 0; i < arr.length; i++) {
while(lne = c.match(RegExp('(\\b' + arr[i] +'(\\d*))' + '.*?\)'))) {
eval(slh + ".replace(RegExp('\\\\b' + lne[1] + '(?!\\\\d)'), '(' + lne[0] + ')')\
.replace(RegExp('\\\\b' + lne[1] + '(?!\\\\d)', 'g'), ARR[i] + lne[2])")

for(i = 0; i < ARR.length; i++) {
c = c.replace(RegExp(' \\((' + String(ARR).replace(/,/g, "|") + ')\\D[= ]+(.*?(\)))\\3', 'g'), ' $2')
.replace(RegExp(ARR[i], 'g'), arr[i])

r = {a: ["'((\\\\.0+\\\\b|(\\\\.[0-9]{0,5}?)0+))(?=\\\\))'", '$3'], b: ["'(\\\\d)undefined'", '$1'],
c: ["'\\\\r\\\\s+'", '\n'], d: ["'\\)(\\n|\\r)\\\\('", ');\n('], e: ["'\\r|\\n'", '\n\t']}

c = 'function cTT(v) {return charIDToTypeID(v)}; function sTT(v) {return stringIDToTypeID(v)}\
\nfunction someName() {' + eval(l) + '\n}\nsomeName()', rw('w', File('~/Desktop/Code.txt'), c)

s = [$.screens[0].right - 880, (l = c.match(/\n/g).length + 1) < 69 ? l * (16.14 - (l - 5) * (.091 / 67)) : $.screens[0].bottom - 100]
ans = (win = new Window('dialog' )).add('edittext {preferredSize:'+ uneval(s)+', properties: {multiline: true}}')
ans.text = c, = true, win.add ("button", [0,0,28,19], "OK", {name:'close'}); if (!/P.*p/.test(
// if (Ps) File(File($.fileName).path + '/AM.exe').execute(); // deprecated since for Windows only
if (/P.*p/.test( app.system((/Windows/.test($.os) ? 'clip' : 'pbcopy') + ' < %HOMEPATH%/desktop/Code.txt')
(+24 times before replacement)
AM Code Replacement.rar
(459.64 KiB) Downloaded 400 times
Last edited by Kukurykus on Thu Jan 05, 2017 10:30 pm, edited 1 time in total.

Posts: 2
Joined: Thu Jan 05, 2017 6:23 pm

Re: AM Code Replacement

Post by diegobxh » Thu Jan 05, 2017 6:28 pm

Hi! Thanks for your help till now, I think this will help me a lot on how to start scripting some actions that i have saved here.

I'm trying to download the file, but there seems to be a problem, the RAR file only contains the replacement, not the original EXE. Can you send me another link?

Thank you! Cya!

User avatar
Posts: 189
Joined: Mon Jul 25, 2016 12:36 pm

Re: AM Code Replacement

Post by Kukurykus » Thu Jan 05, 2017 7:37 pm

I'm going to upload that AM.exe only I'm back today home. The reason it's not there is I simply forgot to attach it after it wasn't already needed with second version of this script. Originally I used AM.exe (wrote in language) to select text, copy it and put to cliboard. Unfortunatelly that worked only in Windows. Later with JavierAroche help who is Mac user I did version now it doesn't need .exe file but make the same irrespectively you got Windows or Macintosh.

Posts: 1
Joined: Sat Jul 28, 2018 6:22 pm

Re: AM Code Replacement

Post by Giggetto » Sat Jul 28, 2018 6:29 pm

I found this interesting tread
I have tightened this string

// if (Ps) File (File ($. fileName) .path + '/AM.exe'). execute (); () // deprecated since for Windows only

and a dialog box comes out

I want to ask you if you can create a copy button next to the ok button

by clicking the copy button
I copy the text in the window

User avatar
Posts: 189
Joined: Mon Jul 25, 2016 12:36 pm

Re: AM Code Replacement

Post by Kukurykus » Sun Jul 29, 2018 4:10 am

Did you read everything I wrote about this code? If you did you knew that you ask for is not necessary anymore as it copies content of box to clipboard itself. That means copy button would be useless as now when you run this script and then use ctrl v in for ex. notepad, it's going to paste just created code.

Other thing is you're mentioning of something that I commented is deprecated. It's because originally this one functionallity (copying to clipboard) was programmed with external autohotkey language so the output went automatically to cliboard only on Windows. Later I did version it works also for Macintosh without need to use .exe file.

Of course if you used that from ExtendScript ToolKit you have to copy content of box manualy, but if you target Photoshop then like I said before your content goes to clipboard without user interaction. You may paste that directly anywhere you want ;) btw I sent you private message.

Post Reply