28 Replies Latest reply on Jan 4, 2017 1:53 AM by SuperMerlin
      • 1. Re: Action Manager (Script Listener) code converter script!
        Jarda Bereza Level 4

        Thanks! It looks useful. It reduces code for creating text layer from 470 line to 174 lines :-) That's 63 % less lines of code.

         

        Is there possibility use String ID instead of Char ID if possible? String IDs are more meaningfull. There should be code which can do that, but the web is not working right now. http://www.tonton-pixel.com/blog/scripts/utility-scripts/get-equivalent-id-strings/

        • 2. Re: Action Manager (Script Listener) code converter script!
          Kukurykus Adobe Community Professional

          Just think of 1000 line code generated with Puppet Warp for example. It would be about 350 lines, however duration of conversion would take probably more than 10 seconds (still better than doing it manually maybe 10 hours :D)

           

          There were few exceptions before my code started to work with every result of Script Listener (I tested so far), but I hope even when someone find something it can't handle it won't be much work to look into by me again to make it for better.

           

          That site you linked let you do probably do the same but with JSON. I knew it but never tried to use any code from that, and the web worked now, unfortunately I assume this guy run his site on home computer server, so it's available when his computer is launched at the moment. Mostly any time I try to visit his site it's down. Now at my polish morning I found there that CharId are possible to be presented as StringId. I wasn't aware of it, however I saw some problem with 'grain' case in the past what is obviously 'Grn ' (CharId), but wasn't so smart to get to know people are saying of StringID sample. So yes, it would be possible to change my code to change charID to StringID. Let me find the way it works and I implement it. Possibly it'll be an option, so for people who prefer it more.

           

          And thank you for giving the credit. It's always nice when some mastered coder do so to that less experienced yet

           

           

          Update: I found a bug as I tried my code first time with a lasso tool, and it gave strange result. I'll fix that later.

          • 3. Re: Action Manager (Script Listener) code converter script!
            JavierAroche Level 3

            Hey Kukurykus, thanks for sharing! I see you're using an exe, does that mean this only works on Windows?

            • 4. Re: Action Manager (Script Listener) code converter script!
              Jarda Bereza Level 4

              Yes some CharIDs are messed up :-) Tonton has page on his site how to solve this this problem. He is looking into context. If "Grn " is inside something, then it means something. If "Grn " is inside something else, then it means something else :-)

               

              The most crazy thing you can test is probably applying liquify on smart object. Because developers forgoten disable action recording in this action. (Usually can't record pating with brushes) and generated code has many thousand lines of code for single action :-D

              1 person found this helpful
              • 5. Re: Action Manager (Script Listener) code converter script!
                Kukurykus Adobe Community Professional

                Well, not exactly JavierAroche . Let me explain intention of using .exe. I have Photoshop 5.1 a home and 6 in work. They both use Flash while CC not anymore(?). So when I wanted to use a script with Photoshop (of course if a Flash was the reason) even when I marked in a code the result text was highlighted in dialog box it wasn't (for example in CS2 it was). Now it was highlighted only when I ran the script in from Extendscript. So I used that AHK script (I think you can't use it on Mac's) it was to highlight the text you couldn't as you see (I don't know how in CC though) by Photoshop script. Then it additionally (that .exe file) copies content of displayed dialog, and finally it presses enter (return), so the window is going to be closed. You have now simply converted code result in your Windows clipboard (memory). So you don't have manually to copy it and close the window. Now you can paste it anywhere you want.

                But don't worry, as far as you use Mac that part of code won't be executed, so the same like that was in Extendscript. My script will finish its work on the part Final Dialog box with (unhighllighted) content will be popped out (I guess). Then you have manuualy to copy a content and close the window.

                • 6. Re: Action Manager (Script Listener) code converter script!
                  JavierAroche Level 3

                  Ah I see! I think there's a way to avoid these 2 external files then, and make it compatible with any OS.

                   

                  You can copy something to the clipboard directly from ExtendScript, with this descriptor.

                  var txt = 'hello world!';
                  
                  var desc = new ActionDescriptor();
                      desc.putString( charIDToTypeID('TxtD'), txt );
                      
                  executeAction( stringIDToTypeID( "textToClipboard" ), desc, DialogModes.NO );
                  

                   

                  By that point, you might not need to highlight your text in your dialog window anymore. But, if you still want to highlight it, you can do it by adding this line to your code:

                  ans.text.active = true;
                  

                   

                   

                  Yes some CharIDs are messed up :-) Tonton has page on his site how to solve this this problem. He is looking into context. If "Grn " is inside something, then it means something. If "Grn " is inside something else, then it means something else :-)

                  Jarda Bereza, this is a little explanation by Tom Ruark as to why stringIDToTypeID('grain') == stringIDToTypeID('green')

                  Determine layer color label from layer id?

                  1 person found this helpful
                  • 7. Re: Action Manager (Script Listener) code converter script!
                    xbytor2 Level 4

                    I have a couple of scripts in xtools that tackle this kind of problem:

                    SLCFix.js : http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xapps/SLCFix.js

                    //

                    // SLCFix.js

                    // This script does some minor massaging of ScriptListener output

                    // primarily by substituting charIDToTypeID and stringIDToTypeID with

                    // cTID and sTID. In the process of doing this replacement, the

                    // 'var id##' style declarations are removed in the c/sTID calls

                    // placed inline. You'll need to copy the c/sTID definitions from

                    // this file into whatever file you decide to use the converted code.

                    //

                    // One other piece of corrective surgery is to canonicalize all

                    // filename strings to use '/' instead of '\' characters. I didn't bother

                    // messing with the drive names.

                    //

                    // The only thing left that I don't really have a solution for is Actions

                    /// that invoke scripts. For some reason, the return value of the script

                    // is placed in the action and gets output to the ScriptingListener log

                    // file as well. Search for 'jsMs' to see what I mean. Unforunately, in

                    // many case, the return value is effectively the last piece of textual

                    // code parsed, I think. There is not an easy way that I have found to

                    // remove this travesty after the fact, except to do it manually by replacing

                    // the code with an empty string, "". You can, however, remove it before

                    // the fact. Make the last line of your script files 'true;' or, like I do,

                    // the name of the script as a string, e.g. "SLCFix.js"; This has the nice

                    // added benefit of showing up in the debugger console if you are running

                    // the script from within the debugger.

                    //

                    // I've converted up to 20,000 lines of ScriptingListenerJS.log code in one

                    // pass with the only problems being the 'jsMs' garbage. That can, as I said

                    // before, be fixed manually.

                    // !!! This may gave been fixed!!!

                    //

                    // $Id$

                    // Copyright: (c)2005, xbytor

                    // License: http://www.opensource.org/licenses/bsd-license.php

                    // Contact: xbytor@gmail.com

                     

                    This handles complete SL log files. There is also an option to use symbolic variables instead of cTID or sTID expressions.

                     

                    There is also http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xapps/LastLogEntry.jsx which I use more frequently. Do something in PS, run this script, hit the Fix button and you get something that is a lot more readable and smaller. Remember, however, that not all actions in PS are recordable.

                     

                    //

                    // LastLogEntry.js

                    // Get the last entry from a ScriptingListenerJS.log file.

                    //

                    // $Id$

                    // Copyright: (c)2005, xbytor

                    // License: http://www.opensource.org/licenses/bsd-license.php

                    // Contact: xbytor@gmail.com

                    //

                     

                    Both of these 'include' other files (like stdlib.js). I you don't have xtools installed, substitute /xapps/ with /apps/ to get a self contained script. I tend to reuse/include previously written code which is why the /apps/ code is a lot thicker than it needs to be. But, then again, I only need to fix a bug or enhance a feature one place instead of five.

                     

                    The scripts handle funky file path stuff and a few other odd things and has been used by Adobe for internal research stuff so I have to assume it is fairly stable in addition to be fairly old but continually refined.

                     

                    It's good to see others do similar  (and more light weight) implementations.

                    1 person found this helpful
                    • 8. Re: Action Manager (Script Listener) code converter script!
                      Kukurykus Adobe Community Professional

                      I fixed wrongly working RegExp, actually I replaced it with one of original parts I used during beta versions but later changed to new one during last phase, "the slimming". Unfortunatelly I found it failed so had to retype it to that worse looking one., (/(\.(0+\b|([0-9]{0,5}?)0+))(?=\))/, '$3') -> (/((\.0+\b|(\.[0-9]{0,5}?)0+))(?=\))/, '$3')

                       

                      Now I'm going to list everything there happens in code. Blue for points seen in final result, and some other colour for those in process but needed all other "blue" steps could be executed.

                       

                       

                      I'm gald even Xbytor showed up, personally for me (just 1,5 year with scripting) one of greatest Gods who remembers "times before time", when there weren't many people you could ask for advice how to do something while the resources were cheap. Honestly if I had to do anything 15 years ago like Xbytor without practising at Codewars for example (where without beeing genius you can learn 2 years material just in few months) that wouldn't be fun but only hard work.

                       

                       

                      Ps. after I finished my code I looked into yours to see differences. But there were 20000 lines! so afer scrolling down and looking for those I needed and still not seeing them I gave up. It's good you showed now in your post link to its essence. I'll analyse that later to see differences. I'm not sure you did some newest version of it but where I looked for (http://ps-scripts.sourceforge.net/xtools.html) your code didn't do so much (looking at sample from that PS CS1? times, nearly 15 years ago!), so after all I would write my own Anyway I believe I have enough time one day to browse everything you wrote, that will be one of best lessons I could ever had learning Photoshop scripting.

                       

                       

                      btw I made a test to see how huge can be reduction. In case of 2 lines you get of course only one but some simple 3 points Puppet Warp on some 3 letters reduced 3866 to 2141 lines of code, what's still not proportional, as there is many lines of numbers which stay unchanged. I cut them from both codes and left only changable code (2558 to 839). Still much, but it's only sample, noramlly I will use it to some regular, shoter actions I do. Ah and the time of this process was a little long, about 30 - 45 seconds! Fortunately mostly with other long codes you want to change for some reason it should be up 7 - 8 seconds.

                       

                       

                      After description I'm going to do that help maybe others I hope to have from them ideas how to enhance this code like for example changing CharID to StringID (Jarda Bereza idea), or replacing AHK script working on Windows only with part I had no idea it exists (JavierAroche told me). I'll check it later, maybe I do something wrong but I tested it in CS5.1 and CS6 and possibly stringIDToTypeID( "textToClipboard" ) wasn't yet implemented but only later in some CC?

                       

                      Ps. I see in other posts that names of users are highlighted for blue and preceded by some blue icon, why it nover happens in my post when I mention other posters?

                      • 9. Re: Action Manager (Script Listener) code converter script!
                        JavierAroche Level 3

                        Based on this forum post, it looks like the textToClipboard stringID was implemented in Photoshop 13.1. I'm not sure if that's accurate.

                        Photoshop JSX -- How do I copy arbitrary text to the clipboard? - Stack Overflow

                         

                        If your Photoshop version doesn't support that stringID, you could always do it through a system command.

                        var thisOS = $.os,
                            systemCommand;
                            
                        var txt = 'hello world!';
                        
                        // Analyze current OS and determine system command
                        if (thisOS.indexOf('Windows') !== -1) {
                            systemCommand = 'clip';
                        } else if(thisOS.indexOf('Macintosh') !== -1) {
                            systemCommand = 'pbcopy';
                        }
                        
                        app.system('echo ' + txt + ' | ' + systemCommand);
                        

                         

                        Ps. I see in other posts that names of users are highlighted for blue and preceded by some blue icon, why it nover happens in my post when I mention other posters?

                        You need to add "@" before the name to tag them.

                        1 person found this helpful
                        • 10. Re: Action Manager (Script Listener) code converter script!
                          Kukurykus Adobe Community Professional

                          @JavierAroche that explains why I couldn't use it in work where I have 13.0 (so PS 6) and the more at my home 12.1 (so PS 5.1). I remembered that long time ago @Paul Riggottwas first one I heard did that and put to his library his scripts on the site its about 3 - 4 months down used. That was in Windows 7 (or earlier) though when CC wasn't released yet. He used system path to a certain file, but when I'm looking at that arbitary solution at StackOverflow that wasn't so obvious to find it out. Maybe becuase of older OS, or maybe I'm completely wrong becasue I didn't see that, just only know what somone said about he he

                           

                          Now I see that was worth of trying myself. it's so easy sooner or later I could find it perhaps without help. Both your and that script at StackOverflow are those I needed. Yupi! Today I won't put it to my script, but shortly I post here alternative script for Jarda Bereza wish who wanted to change all Chars to Strings.

                           

                          Regarding @name. I found it too before, but if I'm not wrong now I see you can't call the person of post you answer to. So in this one it won't work, only for others :/

                           

                           

                          Update: hah, strange, during posting there wasn't your name, and now there's still not. I added your name but untill it's posted it doesn't seem be displayed a way it should. For Paul it didn't worked, maybe because he doesn't post here anymore...

                          • 11. Re: Action Manager (Script Listener) code converter script!
                            xbytor2 Level 4
                            Ps. after I finished my code I looked into yours to see differences. But there were 20000 lines! so afer scrolling down and looking for those I needed and still not seeing them I gave up

                             

                             

                            In my app scripts (not lib scripts). Start at the bottom. There is (almost) always a main() function and you can dig into it from there.

                            The most important file is xtools/xlib/stdlib.js (at about 10,000 lines of code).  That's where I started putting useful stuff in the beginning (back in the days of PS7 and no ScriptUI). psx.jsx is a stripped down version of stdlib.js that I used for ImageProcessorPro. It also has a bunch of ZStrings and localization code.

                            1 person found this helpful
                            • 12. Re: Action Manager (Script Listener) code converter script!
                              Kukurykus Adobe Community Professional

                              Regarding to Jarda Bereza request I added to my script a RegExp part it changes all CharsId to StringsId for ex. 'slct' to 'select'. It took only one new line, however I changed it temporarily to three. You find:

                               

                              if ((Ps = /P.*p/.test(app.name)) && lne[3] == 'c') {
                                lne[2] = "sTT('" + eval(lne[2].replace(/cTT(.*)/, 'typeIDToStringID(charIDToTypeID$1)')) + "')"
                              }
                              

                               

                              in part of original code:

                               

                              while(lne = c.match(/(\w+) = ((s|c)TT\('#?[\w ]*'\))/)) {
                                eval((slh = "c = c.replace(RegExp(lne[0].replace(/(?=\\()/, '\\\\').replace(/(?=\\))/, '\\\\')), '')")
                                + ".replace(RegExp(lne[1] + '(?=,|\\\\))' + '\\\\b'), lne[2])")
                              }
                              

                               

                              that now as combined codes it looks as follows:

                               

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

                               

                               

                              In my opinion a converted ScriptListener code with StringId only is now more understandable for someone new, but for those playing with Ps scripting some more time CharsId makes a transformed SL code looks more readable.

                               

                              So if some of you want a result to be mix of strings and chars you can put that new part into /**/. Please remember that now each time running  "AM Code Replacement" scirpt from ExtendScript it won't use that additional part, as to convert chars to strings Photoshop must be working (and be pointed) at same time. An alternative would be to make a library of all string names, so it let you to get the same result without lanched Photoshop.

                               

                              For those who for some reason need both version but they don't want each time to preceed with doubled slashed i.e. // new code lines, there could be an option to choose in the popped dialog (right after running a script) would you like all Strings or both Strings and Chars in the result to get. Alternatively that could be displayed right before final pahse of script what I tried to do originally 2 days ago. I did so, but unfortunatelly a time of changing Chars to Strings took more time that sole script without that current bonus part. Now if you use a timer and run a script with some really long code you only had a chance to notice a diference in time of conversion (plus 1 - 2 seconds). If someone say it's worth of adding that option (right after running a script) to ask how the result have to be got I'm waiting for propositions, because maybe there is other way to do that instead of having each time that popping dialog while most of users won't need it; so maybe some .txt preferences file? It's a question only for next 2 weeks before I finish a job with this script to start some new project

                               

                              The next what I'm going to make with this script is almost ready part changing AHK script to a more integrated part JavierAroche asked for (coppying a code result to clipboard), so working both on Windows and Macintosh OS.

                               

                              btw thx xbytor2 for advice about how to browse your scripts

                               

                              Ps. I found why I couldn't mention Jarda Bereza in the post beeing an answer to him:
                              - because it displays only other users names during answering to that person post
                              - if someone has whitespace in his username you must replace it with underscore: _
                              /(\w+) = ((s|\('#?[\w ]*'\))/

                              An Idea to Jive: would be great if all RegEx like for ex.

                              /(\w+) = ((s|c)TT\('#?[\w ]*'\))/
                              

                              got some other than black regular text colour. Not blue like those quoted parts, but different like in ExtendScript (not for CS2 version where RegEx had alike quoted parts colour). There is other coloud for text, quotes and regex, while here you have even blue lines of regex if that part of it got quotes although surrounding parts are still black like normal text. I mean entire regex lines (not RegExp('something')) should get one colour, but different than regular text and quotes.

                              • 13. Re: Action Manager (Script Listener) code converter script!
                                Jarda Bereza Level 4

                                Thanks for string IDs.

                                 

                                List of all strings ID can be done with method known as brute-force attack. CharId has always four characters... so you are trying all combinations and you are checking if you got result. It took cca 5 minutes on realatively fast PC. Tonton (link above) has script for this.

                                 

                                Anyway I always have my PS runing.

                                 

                                Btw aren't regex usualy a bit slow?

                                • 14. Re: Action Manager (Script Listener) code converter script!
                                  Kukurykus Adobe Community Professional

                                  Haha I learnt much things thx to sharing my script with others:

                                   

                                  - Jarda Bereza told me there is way to change all charsId's to stringsId's (I found later in Paul Riggott post how to do that)

                                  - JavierAroche showed me how to not use external AHK scripts to select all & copy to clipboard as there is non-built-in method to do it even in older Photoshops

                                  - some things I got to know from xbytor2 plus other little stuff and now I know what cca stands for ha ha, it's a circa (around, about), and what is brute-force attack

                                   

                                  I want to say opensourse you share your scripts in is a good idea. You never know what's good you get back for. So far I haven't tried to ask of anything, but did myself even if I couldn't find an answer. Well, time to change attitude

                                   

                                  Jarda Bereza, I'd like to answer yes or no, but I have no idea. I have no fundamental knowledge. Probably I wouldn't do much mistakes if I started off from zero my education with programming. When I didn't know something like RegEx (not only JavaScript's) exists I created loops in loops in loops ..... in loops ... ha ha and neverending Arrays... Well some of my scripts were so long that I couldnt get to know what and where is exactly inside and I even found most of them were something like beeing type of 'fake' regex. Then I removed all of them and started to learn RegEx for few months (and nothing else). Now I'm able to write everything I did before by 30 lines, maybe just in 3 short, or 1 long? I don't know what is alternative for RegEx, but if I had to use those loops and arrays again that would be step back. Only one thing I know for sure there are fast working regex and slow working. All is about your goal and text your looking thru. If it's short text there is no matter you use inside RegEx between other things: .* (so mark all), but the longer text the more often you must avoid .* as searching thru will take long minutes. So when you specify what you are looking for, or what you want to ommit, the same regex without .* but with some other even short 'command' make those minutes process change to ONE second, in fact. An example to proove it.

                                   

                                  If in the code from my previous post, so:

                                  while(lne = c.match(/(\w+) = ((s|c)TT\('#?[\w ]*'\))/)) {
                                    eval((slh = "c = c.replace(RegExp(lne[0].replace(/(?=\\()/, '\\\\').replace(/(?=\\))/, '\\\\')), '')")
                                    + ".replace(RegExp(lne[1] + '(?=,|\\\\))' + '\\\\b'), lne[2])")
                                  }
                                  

                                   

                                  you replace this part:

                                  /(\w+) = ((s|c)TT\('#?[\w ]*'\))/
                                  

                                   

                                  with this:

                                  /(\w+) = ((s|c)TT(.*)\))/
                                  

                                   

                                  or even worse:

                                  /(\w+) = (.*)(\n|$)/
                                  

                                   

                                  you would feel like you work on the computer from early '90 years! as that few second of searching through long code wouldn't take few secs but 10 or more minutes, however if your computer woulnd't explode meantime it'd finish its job.

                                   

                                   

                                  If there is some other non RegEx method to use I'd like to be fully acquainted with - please let me get mastered the use of IT

                                  • 15. Re: Action Manager (Script Listener) code converter script!
                                    Jarda Bereza Level 4

                                    I seen mention about some JS library which has nice function for text operations: https://vocajs.com/

                                     

                                    Maybe this javasript could work also in Photoshop Script Engine.

                                     

                                    Disadvantages of complex regex is that anybody except you can't read it easily and after half year or one year even you can't read it easily :-)

                                    1 person found this helpful
                                    • 16. Re: Action Manager (Script Listener) code converter script!
                                      Jarda Bereza Level 4

                                      I don't know why, but Photoshop crashes everytime I am using this script from Extension Sctip Toolkit CC

                                      • 17. Re: Action Manager (Script Listener) code converter script!
                                        Kukurykus Adobe Community Professional

                                        Yes that's fact, at least in case of ExtendScript provided with CS 5.1 and CS 6.0. I don't konw it's a same case with later Phosothop (CC) versions, I mean last Extensdscript, but what I know is:

                                         

                                        You can't run this script without pointing Photoshop. Sole Extendscript doesn't suffice to read property of Photoshop, so those Char and String long codes. Trying it outside of Photoshop fails as it must connect to Ps "library" to use strictly coded methods (or how to name it) like char/stringIDToTypeID used by Photoshop. I believe it's question of something else so I mention this all just in case, as it's probably obvious for most of us. The same you can't make rotaion of anything ran in Extendscript if there's no for example #target photoshop at top of sheet in extendscript editor.

                                         

                                        I'm sorry for that I didn't do everything else I described before about enhancing this script (for example making all systems compatibile for selecting, copying and pasting (with JavierAroche help ), other little stuff but meantime I started new project, and it's nice to say it's thanks to that one post of you which inspired me to that Jarda Bereza. Because most time Mikaeru69 site is down and I couldn't at least check how work his script translating chars to strings so I wrote it last days myself. Probably today / tomorrow I post it and I'm happy to say it takes only 1 minue to get the same result you said it takes 5 minutes with Mirakeu script, and just 1,5 minute if you want to have progress bar (not only letters and numbers of course it sees). There is also stuff to break and close script, so if an ESC key was pressed by bad luck, you can continue a progress from place that was stopped, or quit.

                                         

                                        Shortly I'll post it. I hope you compare it with Mirakeu script to tell me differences, as I really respect this guy for his work and I'm happy my abilities let me beat him in case of this one script by time factor or maybe his script does much more things and it's why it took longer time to fully finish its tasks.

                                         

                                        Ps.1 regarding crashes, the current script I'm in last phase when broke (but previously been ran from Extendscript to be released in Photoshop) can't be continued. It highlights some codes for red. If you run it from Photoshop it's fine, you can choose a script to be stopped or continued. And it's not a question of lack of try...catch statement or $.levels = 0 put only for Extendscript use. If anyone can say how to avoid it, please tell us

                                         

                                        Ps. 2 it's always good practise to put alerts in your script when you can't fastly realise where the bug is. You ran a script and check which alerts popped up. If some did not, you can narrow down your searching to that specific part if you still do not know what casued a crash. Then you can experiment changing values, removes some part of that code etc. At least it's what I would've done about it. If it's question of RegExp differently read by Extendscript than Photoshop then tell me what part the latest you could reach testing this way a script and I'll see what I can change to make it working for CC too.

                                         

                                        Ps.3 I know where to download it but can I use Extendscript CC with CS 5.1 or 6.0 ?

                                         

                                        Ps. 4 maybe one day I'll try vocajs, unfortunatelly I have so many programs to check on my list that present day I just focus on that I have to do or there is really something important I had to check immediatelly. But that's true, when someone uses simple Regex as little help to his codes then it's almost impossible to understand quickly what someobody wanted to "say" by his Regex, especially when you don't even know what it had to be used for. Personally I love narrowed codes, so I use Regex and eval quite much. It's my point to gather many information on short text but still I try to make it easy to read for those more experienced scripters. probably with some years of practise. btw I saw some dedicated RegEx sites. People are really crazy - they love Regex so much that learn it more than they can later use it and, it's more about sole regex than coding If I had time I would be in this group too probably, at least I'm happy I could practise al Regex exercises of different levels of hardness for few months in Javascripts on codewars.com. Another place where you can forgot what you started with coding for and you may get used enough of doing it on there that only one goal is trying to slove next somebody's scripts to be higher in ranking or playing with it to have fun like from solving crossword puzzles :/

                                        • 18. Re: Action Manager (Script Listener) code converter script!
                                          Kukurykus Adobe Community Professional

                                          JavierAroche I found it's very easy and useful. I'm going to learn everything I can do by system() shortly. But now I have 2 questions to you.

                                           

                                          1) I like your solution when you take to clipboard a content taken to variable. It would be all fine if it wouldn't read only first line of some text taken to variable. Do you know any method or parameter I could use in shortened version of your code it took all content of that c variable (so not only first line) to clipboard?

                                           

                                          app.system('echo ' + c + ' | ' + (/Windows/.test($.os) ? 'clip' : 'pbcopy'))
                                          

                                           

                                           

                                          2) I found something I'm going to use if I don't find answer for the first question. The problem is I don't know it will be working on Macintosh. There is something like it (depending of a file path): clip < code.txt

                                           

                                          This short line takes to clipboard entire content of some .txt file from current directory or pointed path. It works for me on Windows, is it so for you on Macintosh?

                                           

                                          Ps. I used ans.text.active = true;  before you adviced it to me, but like I said it works only in Extendscript, in Ps CS 5/6 it doesn't (however what is strange it works designed way in CS2). Could you tell me is it working on the newest CC? or it's perhaps Macintosh comfort?

                                          • 19. Re: Action Manager (Script Listener) code converter script!
                                            JavierAroche Level 3

                                            Hey Kukurykus, try wrapping your c variable in quotes, like this:

                                            app.system('echo "' + c + '" | ' + (/Windows/.test($.os) ? 'clip' : 'pbcopy'))
                                            

                                             

                                            2) I found something I'm going to use if I don't find answer for the first question. The problem is I don't know it will be working on Macintosh. There is something like it (depending of a file path): clip < code.txt

                                            I just tested this on macOS Sierra and it works using pbcopy. I think both options are effective. I avoid creating temporary files in the user's system, but it is an acceptable solution.

                                            pbcopy < code.txt
                                            

                                             

                                            Ps. I used ans.text.active = true;  before you adviced it to me, but like I said it works only in Extendscript, in Ps CS 5/6 it doesn't (however what is strange it works designed way in CS2). Could you tell me is it working on the newest CC? or it's perhaps Macintosh comfort?

                                            I only have Photoshop CC2015 and CC2014. I just tested this and it works on 15, but not 14

                                            var myWindow = new Window ("dialog"); 
                                            var myText = myWindow.add ("edittext", undefined, "Hello world");
                                            myText.active = true; 
                                            myWindow.show ();
                                            
                                            • 20. Re: Action Manager (Script Listener) code converter script!
                                              Kukurykus Adobe Community Professional

                                              Well, that solution with additional quotes doesn't work. It only add quotes to content of variable, but still of first line.

                                               

                                              I was really close now, and I hoped it will work in Photoshop, but unfertunately there are some commands working in command line editor only.

                                               

                                              For example when I'm in Command line: more "%HOMEPATH%\desktop\Code.txt | clip" (without quotes) copy content of Code.txt without opening visually a file and without pasting output in cmd editor. But when I use ctrl v anywhere it works! And it's nice that I don't have to specify user name thx to %HOMEPATH%. It's pity when I do System(more %HOMEPATH%\desktop\Code.txt | clip) by extendscript with ran Photoshop nothing is copied to clipboard

                                               

                                              I keep learnning command line and maybe I find something it won't see only first line. For example, today earlier I tried RegExp, but failed again. Only one I could do was to put whole text to one long line, but that is not we want...

                                               

                                              I don't think to find any other solution before PS  version 13.1 to to make it working without .bat file. But here's comes an idea. I never used macintosh but I assume there is equivalent file of .bat, isn't there? I so I'm going to write a script will run .bat (or that I cretaed via AHK) file in Windows and appriopate file from OSX, let me only to create that .bat file. Maybe it's not worth of effort, but I hope it let other people (not much though ) to use it a way it was meant.

                                               

                                               

                                              Btw I found there is no srting for charIDToTypeID( "GEfk" )

                                               

                                              function cTT(v) {return charIDToTypeID(v)}; function sTT(v) {return stringIDToTypeID(v)}
                                              
                                              function someName() {
                                                (dsc1 = new ActionDescriptor()).putEnumerated(sTT(''), sTT(''), sTT('diffuseGlow'))
                                                dsc1.putInteger(sTT('graininess'), 10)
                                                dsc1.putInteger(sTT('glowAmount'), 5)
                                                dsc1.putInteger(sTT('clearAmount'), 10)
                                                executeAction(sTT('diffuseGlow'), dsc1, DialogModes.NO);
                                              }
                                              someName()
                                              

                                               

                                               

                                              Is it possible? Aren't strings converted to chars? It is so with other few filters I tried (same chars). To be sure I tried also simple way to check it and it doesn't work too (CS 5.1): typeIDToStringID(charIDToTypeID('GEfk')) <--- it gives undefined!

                                               

                                              Now I'll have to change a script to keep this specific char as there is no string instead, or I'll find there are some others to restrict them too.

                                              • 21. Re: Action Manager (Script Listener) code converter script!
                                                JavierAroche Level 3

                                                That's weird that the quotes don't work.

                                                 

                                                After I run this code:

                                                var c = [];
                                                
                                                c.push('\n' + 'line 1');
                                                c.push('\n' + 'line 2');
                                                c.push('\n' + 'line 3');
                                                
                                                app.system('echo "' + c + '" | ' + (/Windows/.test($.os) ? 'clip' : 'pbcopy'));
                                                

                                                 

                                                I get this in my clipboard:

                                                line 1,
                                                line 2,
                                                line 3
                                                

                                                 

                                                 

                                                And it's nice that I don't have to specify user name thx to %HOMEPATH%. It's pity when I do System(more %HOMEPATH%\desktop\Code.txt | clip) by extendscript with ran Photoshop nothing is copied to clipboard

                                                You can use "~" instead of %HOMEPATH%. On Windows you'll need to use clip.

                                                This works for me:

                                                app.system('pbcopy < ~/Desktop/Code.txt');
                                                
                                                • 22. Re: Action Manager (Script Listener) code converter script!
                                                  Kukurykus Adobe Community Professional

                                                  I just tried it and something must goes bad on my computer, because it still doesn't work.

                                                   

                                                  I think I know what is going on, but it's only suspicion. When I open Command Line all works fine with clip < %HOMEPATH%/desktop/Code.txt. But when I do the same ie. app.system('clip < ~/Desktop/Code.txt') from Extendscript I see that Command prompt is opening. It whizzes by on the screen too fast to read. I think that might be the reason, that it's too fast to copy a content to clipboard, because when I'm doing it in Command Prompt directly it takes noticably a short while longer. After all it opens the same Command Prompt from extendscript I would've do manually, right? So the result should be the same.

                                                   

                                                  Then I have technical question. How to slow down the process of opening Command Prompt when I do it from Extendscript, even let it stay for 2 - 3 seconds before it closes? is it possible, anyone knows it?

                                                   

                                                   

                                                   

                                                  app.system('clip < %HOMEPATH%/desktop/Code.txt') is what I looked for !!!

                                                   

                                                  but why it didn't work any time before I tried it :/ I don't know, and why variable content  don't work still to be copied to clipboard, I don't know too.

                                                   

                                                  • 23. Re: Action Manager (Script Listener) code converter script!
                                                    Kukurykus Adobe Community Professional

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

                                                     

                                                    Now the second update is for JavierAroche. 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.

                                                     

                                                    Ah and probably I resign from description of that what happens in a script in every next line. There are more important scripts I do want to focus on. So if there won't be any serious bugs I recoginse this script as finished.

                                                    • 24. Re: Action Manager (Script Listener) code converter script!
                                                      SuperMerlin Level 5

                                                      Just another option for Wndows users for get/set clipboard and a new version of system that returns the results is modified External Lib example in the bridge SDK

                                                      Bridge Developer Center | Adobe Developer Connection

                                                      BasicExternalObject

                                                      This modified code was written by Paul Riggott, shame to lose it.

                                                       

                                                      #include "BasicExternalObject.h"
                                                      #include "SoSharedLibDefs.h"
                                                      #include <string>
                                                      #include <windows.h>
                                                      #include <stdio.h>
                                                      #include <iostream>
                                                      
                                                      #if defined (_WINDOWS)
                                                          #pragma warning(disable : 4996) // Turn off warning about deprecated strcpy on Win
                                                      #endif
                                                      
                                                      /**
                                                      * \brief To allow string manipulation
                                                      */
                                                      using namespace std;
                                                      
                                                      /**
                                                      * \brief Utility function to handle strings and memory clean up
                                                      *
                                                      * \param s - The referenced string
                                                      */
                                                      static char* getNewBuffer(string& s)
                                                      {
                                                          // Dynamically allocate memory buffer to hold the string 
                                                          // to pass back to JavaScript
                                                          char* buff = new char[1+s.length()];
                                                          
                                                          memset(buff, 0, s.length()+1);
                                                          strcpy(buff, s.c_str());
                                                      
                                                          return buff;
                                                      }
                                                      
                                                      
                                                      extern "C" BASICEXTERNALOBJECT_API long systemCmd(TaggedData* argv, long argc, TaggedData* retval)
                                                      {
                                                          // The returned value type
                                                          retval->type = kTypeString;    
                                                          // Accept 1 and only 1 argument
                                                          if(argc != 1)
                                                          {
                                                              return kESErrBadArgumentList;
                                                          }
                                                      
                                                          // The argument must be a string
                                                          if(argv[0].type != kTypeString)
                                                          {
                                                              return kESErrBadArgumentList;
                                                          }
                                                      
                                                      char*  cmd = (argv[0].data.string); 
                                                          FILE* pipe = _popen(cmd, "r");
                                                          if (!pipe) retval->data.string = "";
                                                          char buffer[128];
                                                          std::string result = "";
                                                          while(!feof(pipe)) {
                                                              if(fgets(buffer, 128, pipe) != NULL)
                                                                  result += buffer;
                                                          }
                                                          _pclose(pipe);
                                                          retval->data.string = getNewBuffer(result);
                                                          return kESErrOK;
                                                      }
                                                      extern "C" BASICEXTERNALOBJECT_API long getClipboard(TaggedData* argv, long argc, TaggedData* retval)
                                                      {
                                                          // The returned value type
                                                          retval->type = kTypeString;    
                                                          HANDLE h;   
                                                        if (!OpenClipboard(NULL)) return kESErrBadArgumentList;  
                                                        h = GetClipboardData(CF_TEXT);
                                                        CloseClipboard();
                                                        if(h){
                                                        string text;
                                                          text = (char*)h;
                                                          if(text.length() < 1) return kESErrBadArgumentList;
                                                          retval->data.string = getNewBuffer(text);
                                                        }else{
                                                      retval->data.string = "";
                                                        }
                                                          return kESErrOK;
                                                      }
                                                      extern "C" BASICEXTERNALOBJECT_API long clearClipboard(TaggedData* argv, long argc, TaggedData* retval)
                                                      {
                                                          if (OpenClipboard(NULL)){
                                                              EmptyClipboard();
                                                              CloseClipboard();
                                                          }
                                                          return kESErrOK;
                                                      }
                                                      extern "C" BASICEXTERNALOBJECT_API long setClipboard(TaggedData* argv, long argc, TaggedData * retval)
                                                      {    
                                                          // Accept 1 and only 1 argument
                                                          if(argc != 1)
                                                          {
                                                              return kESErrBadArgumentList;
                                                          }
                                                      
                                                          // The argument must be a string
                                                          if(argv[0].type != kTypeString)
                                                          {
                                                              return kESErrBadArgumentList;
                                                          }
                                                      
                                                      string source = (argv[0].data.string); 
                                                      int len = source.length() +1;
                                                      source = source.c_str();
                                                      if(OpenClipboard(NULL))
                                                      {
                                                          HGLOBAL clipbuffer;
                                                          char * buffer;
                                                          EmptyClipboard();
                                                          clipbuffer = GlobalAlloc(GMEM_DDESHARE, len);
                                                          buffer = (char*)GlobalLock(clipbuffer);
                                                          strcpy(buffer, LPCSTR(source.c_str()));
                                                          GlobalUnlock(clipbuffer);
                                                          SetClipboardData(CF_TEXT,clipbuffer);
                                                          CloseClipboard();
                                                      }
                                                      
                                                          return kESErrOK;
                                                      }
                                                      /**
                                                      * \brief Free any string memory which has been returned as function result.
                                                      *
                                                      * \param *p Pointer to the string
                                                      */
                                                      BASICEXTERNALOBJECT_API void ESFreeMem (void* p)
                                                      { 
                                                          delete(char*)(p);
                                                      }
                                                      
                                                      /**
                                                      * \brief Returns the version number of the library
                                                      *
                                                      * ExtendScript publishes this number as the version property of the object 
                                                      * created by new ExternalObject.
                                                      */
                                                      BASICEXTERNALOBJECT_API long ESGetVersion()
                                                      {
                                                          return 0x1;
                                                      }
                                                      
                                                      /**
                                                      * \brief Initialize the library and return function signatures.
                                                      *
                                                      * These signatures have no effect on the arguments that can be passed to the functions.
                                                      * They are used by JavaScript to cast the arguments, and to populate the
                                                      * reflection interface.
                                                      */
                                                      BASICEXTERNALOBJECT_API char* ESInitialize (const TaggedData ** argv, long argc) 
                                                      { 
                                                          return "makeArray,getAverage,appendString_s,myScript_a,acceptBoolean_b";
                                                      }
                                                      
                                                      /**
                                                      * \brief Terminate the library.
                                                      *
                                                      * Does any necessary clean up that is needed.
                                                      */
                                                      BASICEXTERNALOBJECT_API void ESTerminate()
                                                      {
                                                          
                                                      }
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      1 person found this helpful
                                                      • 25. Re: Action Manager (Script Listener) code converter script!
                                                        Kukurykus Adobe Community Professional

                                                        Like I mentioned in some post of this topic I heard of this code of Paul Riggott. Unfortunately that was after he closed his site where were some libraries his code used. Probably it's the same code because I see there are include statements on top. I tried to run it but can't because it tries to include files they don't exists Could you please provide us with rest of your repositry regarding above script, thx!

                                                        • 26. Re: Action Manager (Script Listener) code converter script!
                                                          xbytor2 Level 4

                                                          The missing 'include' files may be in the PS C/C++ SDK.

                                                          1 person found this helpful
                                                          • 27. Re: Action Manager (Script Listener) code converter script!
                                                            Kukurykus Adobe Community Professional

                                                            Ah right, I thought so but it was unusual for me, as I thought those libraries were created by Paul Riggott. Now I see he used those SDK to his scripts. THX!

                                                            • 28. Re: Action Manager (Script Listener) code converter script!
                                                              SuperMerlin Level 5

                                                              Yes the code shown is a replacement for the "BasicExternalObject" example in the SDK.