• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Register the path of a file in the dialog box!

Engaged ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Good afternoon people! A happy year of 2018 for all of this community

How do I add to my script some command that allows me to register the path of the last opened file every time I open the dialog box. This will help me a lot because sometimes I need the same image and it becomes very tiring to do the entire localization process. Thank you

Screenshot_1.jpg

This is the script I'm using!

var dlg = new Window("dialog", "PS-fxrios Canecas", {x:0, y:0, width:290, height:160} ,{closeButton: true});

dlg.center();

var openFile = dlg.add('panel', {x:20, y:20, width: 241, height: 115}, 'Add new file');

CkeckAdd = openFile.add('checkbox',{x:15, y:20, width:93,height:25},'Import new File'); 

btn_localFile = openFile.add('button',{x:115, y:20, width:107,height:25},'Locate file'); 

btn_localFile.enabled = false;

btn_import = openFile.add('button',{x:15, y:70, width:207,height:25},'Import OK'); 

btn_import.enabled = false;

caminho = openFile.add('statictext', {x:15, y:45, width:207,height:25} ,'~/Campaign of the last added image');

caminho.enabled = false;

/////////////////////////////////

CkeckAdd.onClick = function (){ 

if(this.value){ 

      btn_localFile.enabled = true;

      caminho.enabled = true;

      btn_import.enabled = true;

     } 

else{ 

       btn_localFile.enabled = false;

       caminho.enabled = false;

       btn_import.enabled = false;

      } 

}

///////////////////////////////

var myFile = myFile

btn_localFile.onClick = function(){ 

myFile = File.openDialog ('Select a sogo file', false); 

if(myFile !=null){caminho.text = myFile.fsName};

};

/////////////////////////////

btn_import.onClick = function(){ 

try{ 

if(CkeckAdd.value&&myFile.exists){ 

       importFile (myFile) }

    catch(e){}   

}

function importFile(file){ 

var descriptor = new ActionDescriptor();

descriptor.putBoolean( stringIDToTypeID( "dontRecord" ), false );

descriptor.putBoolean( stringIDToTypeID( "forceNotify" ), true );

descriptor.putPath( charIDToTypeID( "null" ), new File(file));

descriptor.putInteger( charIDToTypeID( "DocI" ), 3944 );

executeAction( charIDToTypeID( "Opn " ), descriptor, DialogModes.NO );

}

dlg.show();

TOPICS
Actions and scripting

Views

4.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 16, 2018 Jan 16, 2018

PTH = "~/Campaign of the last added image";

(function DLG(v) {

     pth = (dlg = new Window('dialog')).add('edittext', undefined, v), pth.alignment = 'center'

     b1 = (grp = dlg.add('group')).add('button', undefined, 'Locate file').onClick = function() {

          if (((fle = decodeURI(File.openDialog('Select file:'))) != 'null') && fle != v) {

               pth.text = fle, (fle = File($.fileName)).open('r'), jsxFile = fle.read().replace

               (/"(.*)"(?=;)/, '"' + pth.text + '"'), fle.clo

...

Votes

Translate

Translate
Adobe
LEGEND ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Kukurykus  escreveu

UI: Remember last path entered 

Hi Kukurykus  really something similar, but I confess I did not understand what the script is for and how it can help me. The whole tip is welcome. Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

1) Over your first script line insert:

PTH = "~/Campaign of the last added image";

2) In current 15th line change '~/Campaign of the last added image' to PTH

3) Change your btn_import.onClick function to:

btn_import.onClick = function() {

     try{

          if (CkeckAdd.value && myFile.exists) {

               importFile(myFile);

               (fle = File($.fileName)).open('r'), jsxFile = fle.read()

               .replace(/"(.*)"(?=;)/, '"' + myFile + '"'), fle.close()

               fle.open('w'), fle.write(jsxFile), fle.close()

          }

     }

     catch(e){}     

}

Ps. myFile in the above code you may change to caminho.text to get longer version of path.

I don't undrstand why you need 3 steps to open file; checking box, locating file, then importing it. Wouldn't be it easier just locating file to display new path & open file? Or just 2 steps (if it's part of some bigger script), so checking box and locating file (without clicking IMPORT button)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Kukurykus the changes I made here, really imported and showed the image and its path correctly, however, if I close the dialog box and open it again, the last path did not remain registered. My wish would be to just click on the "Import OK"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

For me it worked using your script. After I chose some path, opened clicking Import button, then closed dialog box and opened again I had already displayed last time chosen path. Check administrative rights for your Ps folder. Maybe there's problem, if you keep your script there, do you?

Right click on your 'Adobe' folder (that in 'Program Files' for 'Windows' users), select last item, so 'properties', then find 'Security' tab, click 'Edit' button and make 'full control' to 'all groups / users' there are listed. Apply changes and OK twice.

You may also make a quick test to see it works:

PTH = "Write anything... and run script again!";

(fle = File($.fileName)).open('r'), jsxFile = fle.read()

.replace(/"(.*)"(?=;)/, '"' + prompt(PTH, '') + '"')

fle.close(), fle.open('w'), fle.write(jsxFile), fle.close()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Screenshot_1.jpg

I followed your tip, but unfortunately I'm out of luck today! Still does not show the old way.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

I edited last post of something you can try... so save that script in Photoshop scripts folder and run from (and outside of) Ps. If it doesn't make changes in script, save that short code on your desktop and try from there. If it still doesn't help, then open your ExtendScript ToolKit and run script from there with Photoshop targeted. If that won't make changes to script, then run it only by ESTK. When worked, ESTK should display prompt of updating current script you accept or deny.

Still doesn't show the old way <- you mean new way, as you want script showed last chosen path with new UI dialog.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Unsuccessfully! Run directly from the Photoshop Script folder. It did not work then I ran it straight from ExtendScript ToolKit also did not work .... I think this should be harder than we imagined.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Did it work from desktop, also when you ran it from outside of Ps? Did you reopen Ps, restart your computer just in case?

I am not doing it, but running Ps as administrator may help? Something blocks your ability to overwrite a file apparently...

Maybe you need additionally to right click on your .jsx file, then in 'General' 'Properties' make empty box to "Only to read", and in 'Security" tab do the same you did for 'Adobe' folder. AFTER you do it try something simpler (run it more than once):

if (!(fle = File($.fileName.slice(0, -3) + 'txt')).exists) {

     fle.open('w'), fle.write('someText'), fle.close()

}

fle.open('r'), txt = prompt(fle.read(), ''), fle.close()

fle.open('w'), fle.write(txt), fle.close()

Try also to create and read & save other .jsx file by your following script (use if twice at least):

if (!(fle = File($.fileName.slice(0, -4) + '2.jsx')).exists) {

     fle.open('w'), fle.write('someText'), fle.close()

}

fle.open('r'), txt = prompt(fle.read(), ''), fle.close()

fle.open('w'), fle.write(txt), fle.close()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

Hello Kukurykus, sorry for the delay!

I did a quick test here with:

That worked:

PTH = "null";

  • PTH = "Write anything... and run script again!"
  •  
  • (fle = File($.fileName)).open('r'), jsxFile = fle.read() 
  • .replace(/"(.*)"(?=;)/, '"' + prompt(PTH, '') + '"'
  • fle.close(), fle.open('w'), fle.write(jsxFile), fle.close() 

How to configure this in the main script

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

You don't cooperate. You didn't answer for previous post. There is lack of information from you. Yestarday that code didn't work, but today it does? Perhpas you needed to restart your machine? Did you put it to your 'Photoshop / Presets' folder, reopen Ps and run the script? Now you say you're getting 'null' result. It's when you simply "type" empty content, right? If you type into blank anything else what's the result? Is that text you typed? You ask how to implement it in the script. All detailed instructions you have already wrote in post from 2018-01-16 00:13.

There is chance that original script you posted and then modificated kept some core information that it can't be overwritten after all. So even when later you allowed Adobe folder for modifications that file behaves like Adobe folder has restrictions.

Open ESTK, open your script (you posted) with modifications I posted (2018-01-16 00:13) and you did. Copy its content, open new tab, paste script content, save with other name in Ps folder. Then reopen Ps and run the script (new name).

Ah, and post your script with my modifications, so we'll see you didn't do any mistake

I shortened your script and added possibility to store new path in first line of code:

PTH = "~/Campaign of the last added image";

pth = (dlg = new Window('dialog' )).add('panel', undefined,

     'Add new file:').add('statictext', undefined , PTH)

function iF(v) {if (v) {

     (dsc = new ActionDescriptor()).putPath(stringIDToTypeID('null'), v)

     executeAction(stringIDToTypeID('open'), dsc, DialogModes.NO);

     (fle = File($.fileName)).open('r'), jsxFile = fle.read()

     .replace(/"(.*)"(?=;)/, '"' + v + '"'), fle.close()

     fle.open('w'), fle.write(jsxFile), fle.close()}

}

dlg.add('button', undefined, 'Locate file').onClick = function() {

     iF(pth.text = File.openDialog('Select file:') || pth.text)}; dlg.show()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

Hi Kukurykus I apologize for not collaborating, you're all right, the real reason is the lack of time even! I'm really overwhelmed with tasks here at work and now that I've been able to read your postings. I like your person because you are kind and persistent, I am happy to count on your immense willingness and willingness to solve our problem.

By ESTK did not work! I saved in the PS scripts folder after I did some testing and it actually worked now.

Two questions:

1º : If the path has been registered, it is essential that there is an "Import OK" button and if it is clicked, the tendency is for the last image to be opened, right? Would it be feasible?

2º :How to delete these digits from the path:% 20 .....% E2% 8%

Thank you very much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

Question TWO: on the example of shortened script from last post you have to change line 7 to:

(dsc = new ActionDescriptor()).putPath(stringIDToTypeID('null'), File(v))

so bracket v value into File, while in line 15 use decodeURI method. Change last lines to:

dlg.add('button', undefined, 'Locate file').onClick = function() {

     iF(pth.text = decodeURI(File.openDialog('Select file:')) || pth.text)

}

dlg.show()

Question ONE is completely ununderstable for me. You must say it in other words because now I can't even guess what you want. Do you referer to your original modified script or just that last one I posted? What do you mean by "path registered' ? That it's displayed in blank of UI dialog, or saved to first line of script? What I remember, script is beeing overwritten of new path right after clicking 'Import Ok' button opens a file (in your original modified script). So tell me what you mean because if it's about your script it works fine, and if you're saying about last posted, there is surely chance to add 'Import Ok' button.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

Follow these steps you will understand:

PTH = "/d/•Library/Img_test (3).tif"; 

 

pth = (dlg = new Window('dialog' )).add('panel', undefined, 

     'Add new file:').add('statictext', undefined , PTH) 

 

function iF(v) {if (v) { 

     (dsc = new ActionDescriptor()).putPath(stringIDToTypeID('null'), File(v))

     executeAction(stringIDToTypeID('open'), dsc, DialogModes.NO); 

     (fle = File($.fileName)).open('r'), jsxFile = fle.read() 

     .replace(/"(.*)"(?=;)/, '"' + v + '"'), fle.close() 

     fle.open('w'), fle.write(jsxFile), fle.close()} 

 

dlg.add('button', undefined, 'Locate file').onClick = function() { 

     iF(pth.text = decodeURI(File.openDialog('Select file:')) || pth.text) 

 

  dlg.add('button', undefined, 'Import OK').onClick = function() { 

  

 

dlg.show()

1: Run this script above I just added the" import OK "button

2: Select an image file

3: Close the dialog window

4: Close the image file that you have recently opened

5: Run script again (Note that the path of the image has been saved)

6: You will add a function to the second button: "import OK" that when clicked,

the same will open the last image.

How would the function of each button in the window:

The "Locate file" button would only have the function of finding an image file in a folder, once you have selected a file, click the "import OK" button to open the image on the screen ... and whenever I need to open the last image, I would just click the "import OK" button

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

PTH = "~/Campaign of the last added image";

(function DLG(v) {

     pth = (dlg = new Window('dialog')).add('edittext', undefined, v), pth.alignment = 'center'

     b1 = (grp = dlg.add('group')).add('button', undefined, 'Locate file').onClick = function() {

          if (((fle = decodeURI(File.openDialog('Select file:'))) != 'null') && fle != v) {

               pth.text = fle, (fle = File($.fileName)).open('r'), jsxFile = fle.read().replace

               (/"(.*)"(?=;)/, '"' + pth.text + '"'), fle.close(), fle.open('w')

               fle.write(jsxFile), fle.close(), dlg.close(), DLG(pth.text)

          }

     }

     b2 = grp.add('button', undefined, 'Import OK').onClick = function() {

          if ((fle = File(pth.text)).exists) open(fle), refresh()

     }

     dlg.show()

})(PTH)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

LATEST

Screenshot_3.jpg

Now it's perfect! Friend Kukurykus, you're a genius. Thank you again for the kindness and for your great patience with me!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines