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

how to close folder

Contributor ,
May 22, 2019 May 22, 2019

Hi experts,

How to make a script for InDesign to close win folder?

something like this:

        var cPath = "~/Desktop/AAA";

        var f = Folder(cPath);

                    f.close();

thanks

regard

John

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

Community Expert , May 22, 2019 May 22, 2019

Hi John,

I don't know much of VBScript, however you can try my stab on the issue, combined pieces picked up from Laubenderand mikeb41294032 also courtesy How to close a specific folder with VBScript? - Stack Overflow

if (File.fs == "Windows")

{

    var myVbScript = '''myfolder = "E:\\Projects"

            Set sh = CreateObject("shell.application")

            For Each w In sh.Windows

                If w.document.folder.self.Path = myfolder Then w.Quit

            Next'''

    app.doScript(myVbScript, Scr

...
Translate
Community Expert ,
May 22, 2019 May 22, 2019

Hi John,

close() and open() are no methods of object Folder with ExtendScript.

I'm not sure, I'm no VB Script expert, but you could perhaps do this with VB Script that will be executed by ExtendScript through method doScript().

Regards,
Uwe

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
Contributor ,
May 22, 2019 May 22, 2019

thank you Uwe

John

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
Advisor ,
May 22, 2019 May 22, 2019

Hi John,

I put this together if you're on a mac

    if(File.fs == "Macintosh"){ 
        var script = 'tell application "Finder"\ntry\n close(container window of folder "AAA" of desktop)\nend try\nend tell'; +
        app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);
   }

Regards,

Mike

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
Community Expert ,
May 22, 2019 May 22, 2019

Hi Mike,

I'm not on a Mac right now so I cannot test this, but I wonder if triple fencing with single quotes like in the code below would work:

if(File.fs == "Macintosh")

{

    var script =

    '''

        tell application "Finder"

      

            try

                close(container window of folder "AAA" of desktop)

            end try

          

        end tell

      

    ''';

  

    app.doScript ( script , ScriptLanguage.APPLESCRIPT_LANGUAGE );

};

That would remove the necessity for ugly line endings.

Regards,
Uwe

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
Advisor ,
May 22, 2019 May 22, 2019

Hi Uwe,

I tested on a mac and your version with the triple fencing with single quotes works too!

Regards,

Mike

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
Community Expert ,
May 22, 2019 May 22, 2019

Hi Uwe,

I can't find any detail on the uses of triple fenced single quotes, can you share some links about it.

-Manan

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
Community Expert ,
May 23, 2019 May 23, 2019

Unfortunately no. I picked this up somewhere here in the forum.

Regards,
Uwe

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
Contributor ,
May 22, 2019 May 22, 2019

Thank you Mike

but how to translate it into vbs version?

John

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
Advisor ,
May 22, 2019 May 22, 2019

John,

I don't know vbscript and have no way to test it but I'll see what I can come up with. Until then, you might be able to work with the snippet below if you know vbs.

if (File.fs == "Windows")  {
    var myVbScript = //vbs code
    app.doScript(myVbScript, ScriptLanguage.visualBasic);
}

Regards,

Mike

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
Community Expert ,
May 22, 2019 May 22, 2019

Hi John,

I don't know much of VBScript, however you can try my stab on the issue, combined pieces picked up from Laubenderand mikeb41294032 also courtesy How to close a specific folder with VBScript? - Stack Overflow

if (File.fs == "Windows")

{

    var myVbScript = '''myfolder = "E:\\Projects"

            Set sh = CreateObject("shell.application")

            For Each w In sh.Windows

                If w.document.folder.self.Path = myfolder Then w.Quit

            Next'''

    app.doScript(myVbScript, ScriptLanguage.visualBasic);

}

-Manan

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
Contributor ,
May 23, 2019 May 23, 2019

Hi Man,

error!

not support

If w.document.folder

John

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
Community Expert ,
May 23, 2019 May 23, 2019

Works just fine for me. Did you change the path to the one relevant to your machine?

-Manan

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
Contributor ,
May 23, 2019 May 23, 2019

Changed.

but not work.

John

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
Advisor ,
May 23, 2019 May 23, 2019

Hi John,

Can you post the code you're trying?

Regards,

Mike

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
Contributor ,
May 23, 2019 May 23, 2019

Hi Man,

some computers are ok.

but some are error.

John

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
Advisor ,
May 23, 2019 May 23, 2019

John,

Could it be a permission issue? Are all computers running the same version of windows??

Regards,

Mike

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
Community Expert ,
May 23, 2019 May 23, 2019

Hi John,

Give us more information, like do you see any similarity in computers on which it does not run. Same OS etc.

-Manan

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
Contributor ,
May 23, 2019 May 23, 2019

Hi Man,

ie problem,

error code 2146827850

something like this:

internet explorer - Object doesn’t support this property or method - Stack Overflow

John

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
Community Expert ,
May 23, 2019 May 23, 2019

This post talks about IE scripting, we are dealing with Windows Shell object. You did not tell, if you see consistent failure in a particular OS version, unless i can reproduce it on my end it will be very difficult to resolve the issue.

-Manan

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
Contributor ,
May 23, 2019 May 23, 2019
LATEST

Thank you Man.

John

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