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

Open Windows folder via scriptUI button

Explorer ,
Apr 03, 2018 Apr 03, 2018

Hello,

I am very inexperienced when it comes to scripting.

I've attempted to make an After Effects interface containing a button that when clicked opens a folder that has been created by the script. The command to open the folder works fine, but when I put it in the button function nothing happens. What am I doing wrong? I'm using a Windows workstation.

Here are the essentials of the code:

app.project.close(CloseOptions.DO_NOT_SAVE_CHANGES);

app.newProject();

main();

function main(){

    var proj = app.project;

    var filePath = "C:\\ScriptUI\\TEST\\subDir\\";

   

    while(Folder(filePath).exists == false){ 

        Folder(filePath).create(); 

        }

   

    //system.callSystem("explorer " + filePath);        //this line works and is re-used in a button function on line 30 where it doesn't work

   

    //-------------------------INTERFACE------------------------------

   

    //window and panel creation

    var dlg = new Window("dialog", "");

    dlg.btnPnl = dlg.add("panel", undefined, "Render finished!");

   

    //buttons

    dlg.btnPnl.openBtn = dlg.btnPnl.add("button", undefined, "Open folder");

    dlg.btnPnl.closeBtn = dlg.btnPnl.add("button", undefined, "Close");

   

    //just giving the user a visual representation of the file path

    var msg = dlg.add("statictext");

    msg.text = filePath;

    //button functions

    dlg.btnPnl.openBtn.onclick = function(){

        system.callSystem("explorer " + filePath);      //same as line 12 but nothing happens this time

        }

   

    dlg.btnPnl.closeBtn.onClick = function(){

        dlg.close();

        proj.close(CloseOptions.DO_NOT_SAVE_CHANGES);

        }

    dlg.show();

    }

Any hints appreciated

TOPICS
Scripting
2.1K
Translate
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

Advocate , Apr 04, 2018 Apr 04, 2018

Quick fix - it's not onclick, but onClick:

dlg.btnPnl.openBtn.onClick = function () {

  // Your magic spells goes here

}

Translate
Advocate ,
Apr 04, 2018 Apr 04, 2018

Quick fix - it's not onclick, but onClick:

dlg.btnPnl.openBtn.onClick = function () {

  // Your magic spells goes here

}

Translate
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
Explorer ,
Apr 04, 2018 Apr 04, 2018

!!!

Thanks Tomas! Can't believe I missed that

It works now. Wonderful!

Translate
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
Advocate ,
Apr 05, 2018 Apr 05, 2018

Just one note about your script. Change this:

while(Folder(filePath).exists == false){

    Folder(filePath).create();

}

to this

if (Folder(filePath).exists === false) {

  Folder(filePath).create();

}

It's safer and makes more sense;)

Translate
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
Explorer ,
Apr 08, 2018 Apr 08, 2018

Appreciate the input! Will do.

I actually changed it to 'while' just before posting here. I figured it didn't make much sense for me to use 'if' without an 'else' statement. But apparently it doesn't matter.

Again, thanks for the pointer!

Cheers

Translate
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 ,
Apr 08, 2018 Apr 08, 2018

If does its thing if the condition evaluates to true, while does its thing while the condition is true, that is it loops forever as long as the condition is true, which in this case means the script will hang if something stops it creating the folder. If you want to make sure that the folder is created before proceding you could check the return value of the Folder().create function.

Translate
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
Explorer ,
Apr 08, 2018 Apr 08, 2018
LATEST

Hi Stib!

I see... Thanks for clearing that up! Much appreciated.

Translate
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