10 Replies Latest reply on May 9, 2011 2:45 AM by BeriliaTubul

    [js] Filter for file in openDialog

    BeriliaTubul Level 1

      Hi,

       

      I have this :

      var myFile = File.openDialog("choose a file (.xml)", xmlFilter);

       

      function xmlFilter(myFile) {

           if (myFile.constructor.name == "Folder") { return true }

           if (myFile.name.slice(-4) == ".xml") { return true }

      return false;

      }

       

      It works almost fine, but when a Folder is shared, we can't clik on it. It's the same thing with shortcut.

      I tried to do this but nothing changed.

      function xmlFilter(myFile) {

          if (myFile.constructor.name != "File") {

              return true;

          }

          else if (myFile.name.slice(-4) == ".xml") {

              return true;

          }

          return false;

      }

      Can someone help me, please?

        • 1. Re: [js] Filter for file in openDialog
          John Hawkinson Level 5
          It works almost fine, but when a Folder is shared, we can't clik on it. It's the same thing with shortcut.

          I tried to do this but nothing changed.

          What OS? I don't understand what it means for a Folder to be "shared" -- what do you mean?

          Anyhow, it's a function, so you can set a breakpoint in it.

          The shortcut/alias thing is easy enough. Just permit all aliases. Also, I would write the function a bit more compactly, like this:

           

          function xmlFilter(myFile) {
               return (myFile.constructor.name === "Folder") ||
                 (myFile.name.slice(-4) === ".xml") ||
                 (myFile.alias);
          }
          

           

          That is, it returns true if the constructor is named Folder, or the file ends in .xml, or alias is true. Otherwise it's false.

           

          To solve your shared folder problem, I would set a breakpoint on the first line of the function, type in the console "myFile.reflect.properties", and then look at all the property values that show up in the Data Browser window of the ESTK. What's different about your shared folder? What property can you use that is true?

           

          Also, it looks to me that even if choices are greyed out, you can still double-click them to navigate. Not so for you?

          1 person found this helpful
          • 2. Re: [js] Filter for file in openDialog
            BeriliaTubul Level 1

            Hi,

             

            For alias, it works just fine, thank you.

             

            I'm on Mac but it would be nice if it was working on windows too. (I have not tested it yet)

            It's difficult to explain what I want because I'm french and I don't know what words I should use (I just traduce "Dossiers partagés" in "shared folders"). I think it's a server.

             

            I'm new to indesign, I don't understand all this :

            To solve your shared folder problem, I would set a breakpoint on the first line of the function, type in the console "myFile.reflect.properties", and then look at all the property values that show up in the Data Browser window of the ESTK. What's different about your shared folder? What property can you use that is true?

            If I didn't have to use this I would be easier.

             

            Thank you

             

             

            Edit : I can't double-click on a grey folder (or file)

            • 3. Re: [js] Filter for file in openDialog
              John Hawkinson Level 5

              Use this version of xmlFilter:

              function xmlFilter(myFile) {
                  $.writeln(myFile.name);
                  var props=myFile.reflect.properties;
                  for (i=0; i<props.length; i++) { $.writeln("\t"+props[i]+"\t"+myFile[props[i]]); }
                   return (myFile.constructor.name === "Folder") ||
                     (myFile.name.slice(-4) === ".xml") ||
                     (myFile.alias);
              }
              

              Look at the ESTK's console and you should see for each file/folder a paragraph like:

              April2011.pdf
                   name     April2011.pdf
                   alias     false
                   created     Sun May 08 2011 17:38:50 GMT-0400
                   error     
                   exists     true
                   fsName     /Users/user/Desktop/April2011.pdf
                   fullName     ~/Desktop/April2011.pdf
                   absoluteURI     ~/Desktop/April2011.pdf
                   relativeURI     /Users/user/Desktop/April2011.pdf
                   modified     Sun May 08 2011 17:38:50 GMT-0400
                   displayName     April2011.pdf
                   path     ~/Desktop
                   parent     ~/Desktop
                   type     ????
                   creator     ????
                   hidden     false
                   readonly     false
                   lineFeed     macintosh
                   length     602374
                   encoding     
                   eof     true
                   __proto__     [object File]
              

               

              Paste the output here for the shared folder you cannot traverse.

              • 4. Re: [js] Filter for file in openDialog
                BeriliaTubul Level 1

                That's awesome!

                I didn't know I could do that!

                 

                Anyway, it didn't helped me much : my server is not detected.

                 

                I guess users will copy/paste what they need before use my script.

                 

                Thank you very much for your help

                • 5. Re: [js] Filter for file in openDialog
                  John Hawkinson Level 5
                  Anyway, it didn't helped me much : my server is not detected.

                  Wait, what?

                  It does not appear in the list at all?

                  Does the parent directory appear before you navigate through it? Does it have special properties?

                   

                  What if you don't use a filter? Wouldn't that be better than cut-and-paste?

                   

                  Does Cmd-****-G work? What if you drag the destination folder into the sidebar in the Finder?

                  More details!

                  • 6. Re: [js] Filter for file in openDialog
                    BeriliaTubul Level 1

                    Yeah, that's weird.

                     

                    It does not appear in the list.

                     

                    Before I was searching "Docs" on my Desktop (I can see it on my Desktop), but when I go where "Docs" really is, "Docs" is detected by your code.

                     

                    Capture d’écran 2011-05-09 à 10.42.46.png

                     

                    Docs

                              name     Docs

                              alias     false

                              created     null

                              error     

                              exists     false

                              fsName     /Applications/Adobe InDesign CS5/scripts/XHTML For Digital Editions/afp:/"ip adress"/Docs

                              fullName     /Applications/Adobe InDesign CS5/scripts/XHTML For Digital Editions/afp:/"ip adress"/Docs

                              absoluteURI     /Applications/Adobe%20InDesign%20CS5/scripts/XHTML%20For%20Digital%20Editions/afp:/"ip adress"/Docs

                              relativeURI     afp:/"ip adress"/Docs

                              modified     null

                              displayName     

                              path     /Applications/Adobe%20InDesign%20CS5/scripts/XHTML%20For%20Digital%20Editions/afp:/"ip adress"

                              parent     /Applications/Adobe%20InDesign%20CS5/scripts/XHTML%20For%20Digital%20Editions/afp:/"ip adress"

                              type     ????

                              creator     ????

                              hidden     false

                              readonly     false

                              lineFeed     macintosh

                              length     -1

                              encoding     

                              eof     true

                              __proto__     [object File]

                     

                    Why created is null and exists is false?

                    • 7. Re: [js] Filter for file in openDialog
                      John Hawkinson Level 5

                      Before I was searching "Docs" on my Desktop (I can see it on my Desktop), but when I go where "Docs" really is, "Docs" is detected by your code.

                      That's peculiar. What if your xmlFilter is just "return true;"? Does it work then?

                      What about the parent directory? Does that work?

                       

                                fsName     /Applications/Adobe InDesign CS5/scripts/XHTML For Digital Editions/afp:/"ip adress"/Docs

                       


                      That's clearly a bit goofy, since the afp (Appletalk Filing Protocol) has nothing do wo with the InDesign XTML export.

                       

                      Why created is null and exists is false?

                       

                      Ah, created is a timestamp. Presumably you have a mountpoint of a remote filesystem and the operating system does not record a timestamp for it. Presumably. And exists is false? Not sure. Perhaps because it is not a "real" file.

                      • 8. Re: [js] Filter for file in openDialog
                        John Hawkinson Level 5

                        Does Cmd-****-G work?

                        That was supposed to be Cmd-Shift-G. Not sure what happened.

                        • 9. Re: [js] Filter for file in openDialog
                          BeriliaTubul Level 1

                          If I just do "return true;" then it works fine.

                          I don't understand what is the parent directory.

                           

                          I just realize that "Docs" doesn't appear in my Desktop. Well, I see it on my Desktop, but I don't see it in the folder "Desktop" in the Finder. So it was normal to not see it the console. (Is it understandable?)

                           

                          Where should I do Cmd-Shift-G?

                           

                          And, to answer to a previous question, the users will need to be "framed" so they can't do mistakes.

                          • 10. Re: [js] Filter for file in openDialog
                            BeriliaTubul Level 1

                            I read again the doc (with more attention) :

                            "The creation date of the referenced file, or null if the object does not refer to a file on disk."

                             

                            So, with this it works fine :

                             

                             

                            function xmlFilter(myFile) {

                                 return (myFile.constructor.name === "Folder") ||

                                   (myFile.name.slice(-4) === ".xml") ||

                                   (myFile.alias) ||

                                   (myFile.created === null) // pour les dossiers qui ne sont pas sur le disque

                                   ;

                            }

                             

                            Thank you very much for your help