Skip to main content
Loic.Aigon
Legend
June 2, 2008
Question

OpenDialog to a specific folder

  • June 2, 2008
  • 26 replies
  • 4393 views
Hi,
I saw this question was discussed already but following the tip, I don't have any success. Moreover I couldn't post in the thread so I have to open this topic. Sorry about that.

Well,
here is the matter :
var myfile = File("\\192.168.1.1\Marketing\17. Produits\COPY\Tiff_CMYK_300dpi\ok\copyripok_uk.tif");
myfile.openDialog(); // > ERROR

/*

File.openDialog() // Works great.

*/

So it's so annoying. Where am I wrong ?
Thanks for help
Loic
This topic has been closed for replies.

26 replies

August 8, 2008
Hi Dave:

Re: We've been trying to tell you that for a few messages now.

I've seen yours and Loic post saying to use Files: *.indd as a filter

But like I mentioned filtering is not the issue.

Using myFolder+"/"+myMask, works perfectly in filtering the files that I need displayed (And what I am hoping to acvhive)

What I cannot manage to achieve is the select multiples files i.e: The third parameter in openDlg.

Thanks so much for responding.

Sincerely appreciate this.

Regards
Norbert
Inspiring
August 8, 2008
myFolder + "/" myMask

Does not look like the right syntax for a filter.

We've been trying to tell you that for a few messages now.

Dave
August 8, 2008
Hi Loic,

Sorry I have not made myself clear.

I should have mentioned that I am using openDlg on WIN JS CS2.

What I am hoping to achive is to multi-select files in a particular folder.

myFile=myDocs.openDlg("Select Files To Open", myFolder+"/"+myMask, true);

The aboove line works right upto displaying all require files in the particular folder but I cannot multi select.

Regards
Norbert
Loic.Aigon
Legend
August 7, 2008
Hi Dave,
Sorry to make you post again. I read quickly you former post and it's true I should have been more attentive to it. Ok I got the idea now.
Thanks a lot for your post and precisions !
Loic
Inspiring
August 7, 2008
Loic,

Did you see my message a few back? It explains the differences between Mac and Windows filters and provides cross-platform code for handing it.

Dave
Loic.Aigon
Legend
August 7, 2008
Hi,
I would say that's because your filter parameter is not as expected.
It should be something like "Files : *.indd".
The filter will only exclude file types that are not the one expected.
So if you want to open a specific file on your hard drive you have to say
app.open(File(mypath)) //mypath is the path to the file
or if you want a indd file in a folder in a more generic way
you say
FIle.openDialog("Pick me","Files : *.indd", true);
hope it helps
Loic

PS : Hey folks, saying that I noticed on my mac that the filter seems to be ignored meanwhile on my pc at work it's taken in account ? Is that something normal ?
August 6, 2008
Hi Loic and Dave,

Thanks for your responses. Filtering files is not an issue.

Loic. I tried adding a third parameter heres the code

myDocs = File(myFolder+"/"+myMask)
myFile=myDocs.openDlg("Select Files To Open", myFolder+"/"+myMask.indd, true);
app.open(myFile)

This doesn't work

Regards
Norbert
Inspiring
August 6, 2008
One odd thing about the Mac side is that no matter what you do, application files are always active, but they're treated as files, not folders, so you can't see into a product package. It's hard to tell if this is deliberate or accidental behavior. It just is.

I'm not sure what happens if you use openDlg with a File that is inside a package -- that might work. I haven't tried it.

Dave
Inspiring
August 6, 2008
If you want to Filter files, and you want your script to work on either platform, then you need to use platform-specific code, along these lines:
(function() {


var myFile = getDocFile();
if (myFile == null) return;
alert(myFile.creator + " " + myFile.type);

function getDocFile() {
// cross-platform document file selector
if (File.fs == "Windows") {
var select = "InDesign documents:*.INDD"
} else {
var select = filterFiles
}
myFile = File.openDialog("Choose an InDesign document:", select);
return myFile;
function filterFiles(file) {
while (file.alias) {
file = file.resolve();
if (file == null) { return false }
}
if (file.constructor.name == "Folder") return true
var extn = file.name.toLowerCase().slice(file.name.lastIndexOf("."));
switch (extn) {
case ".indd" : return true;
default : return false
}
}
}
}())
If you've not seen an anonymous function before, don't be put off. Wrapping a script in an anonymous function protects the global name space.

Notice the filtering mechanism. Windows users have it easy. Just get that string right and Windows does the whole job for you (although if you look across a network to a Mac disk that has aliases on it, Windows won't be able to service those for you).

Mac users have to deal with aliases (that's what the while loop is about -- resolving until it either finds a file or a broken alias). Then keeping folders active.

This particular code doesn't work if you have files on your Mac disks that lack extensions, but that's so 20th Century.

The most common mistake Windows users make (or, to be more honest, I make when I'm doing the Windows string) is to forget the prefix. If you hand Windows a string like: "*.EPS, *.TIF" you'll get the wrong File dialog and the one you get is much harder to work with. You need something like: "Graphics files: *.EPS, *TIF".

In this example, I've used the filter with openDialog, but the same approach can be used with openDlg (which takes the same three arguments -- albeit, I've only used the first two in this example).

Dave
Loic.Aigon
Legend
August 6, 2008
File.openDialog (prompt, filter, multiSelect)
so
File.openDialog ("Pick me...", undefined, true) //Undefined when the parameter is not required.
Hope it helps