Return some chars from my code. Photoshop. JSX. ESTK

Hello, everybody!

JSX script work under Photoshop.

I try to write a Method(position or numLine), which return char from my code. Why I want to do this? - Protection --javascriptresource-- section from changes.

I try to make this code, which must return a char from my code:

returnCharFromMyCode(5);

function returnCharFromMyCode(position){
    var fileWithMyScript = new File($.fileName);
    return fileWithMyScript.readch(position);
}

But this primitive code return nothing.

May be, I don’t understand how work read(), readch() & readln() methods?
May be this is bad idea to read script as file, and anybody understand how to return a part of code use other logic?

I was just writing a file process. Here are the points that make that code work.

  • Need to open/close a file
  • Specify position via seek
returnCharFromMyCode(5) ;

function returnCharFromMyCode(position) {
  var fileWithMyScript = new File($.fileName) ;

  var res ;
  try {
    fileWithMyScript.open('r') ;
    fileWithMyScript.seek(position) ;
    res = fileWithMyScript.readch() ;
  } catch(e) {
    alert(e) ;
  } finally {
    try {fileWithMyScript.close() ;} catch(e) {}
  }

  return res ;
}

If you are just protecting the code from change, Export as Binary may be sufficient.

Thank you!

Your code work correctly.

About protecting the code, I understand about JSXBIN. But javascriptresource become unreadable to Photoshop.

What I do to write JSXBIN with javascriptresource:

<javascriptresource>
    <name>Script Name</name>
    <menu>filter</menu>
    <about>about script</about>
    <category>script cathegory</category>
</javascriptresource>

eval("""@JSXBIN@ES@2.0@MyBbyBn.... code from jsxbin file .....""")

And in JSXBIN part I’ll use this method.

1 Like

This looks like javascript code to me, not uxp
see if you can solve it on this forum.