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