Discussion:
OpenDialog to a specific folder
(too old to reply)
Norbert D'souza
2008-08-05 23:58:57 UTC
Permalink
Hi Loic/Bob,

Using openDlg, is there a parameter to select multiple files?

Regards
Norbert
loic_aigon
2008-08-06 08:27:45 UTC
Permalink
File.openDialog (prompt, filter, multiSelect)
so
File.openDialog ("Pick me...", undefined, true) //Undefined when the parameter is not required.
Hope it helps
D***@adobeforums.com
2008-08-06 12:43:46 UTC
Permalink
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
D***@adobeforums.com
2008-08-06 12:46:33 UTC
Permalink
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
Norbert D'souza
2008-08-07 00:25:30 UTC
Permalink
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
loic_aigon
2008-08-07 08:15:53 UTC
Permalink
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 ?
D***@adobeforums.com
2008-08-07 11:45:19 UTC
Permalink
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
2008-08-07 12:37:43 UTC
Permalink
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
Norbert D'souza
2008-08-08 01:32:46 UTC
Permalink
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
D***@adobeforums.com
2008-08-08 01:38:47 UTC
Permalink
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
Norbert D'souza
2008-08-08 01:52:32 UTC
Permalink
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
Norbert D'souza
2008-08-08 02:07:14 UTC
Permalink
Hi Dave,

I just tried the code on CS3 and it allows me to select multiple files.

So I am guessing that the code does not work for CS2 to multi select.

However, in CS2's user interface when I do a File---> Open, it allows me to do a multi select.

Any suggestions?

Regards
Norbert
loic_aigon
2008-08-08 07:07:04 UTC
Permalink
Have a look on page 540 of the Indesign CS2 scripting reference :
openDialog
File.openDialog
([prompt][,select])
prompt
Optional. A string containing the prompt text, if the dialog allows a prompt.
select
Optional. A file or files to be preselected when the dialog opens:
In Windows, a string containing a comma-separated list of file types with descriptive
text, to be displayed in the bottom of the dialog as a drop-down list from which the user can select which types of files to display.
Each element starts with the descriptive text, followed by a colon and the file search masks for this text, separated by semicolons. For example, to display two choices, one labeled Text Files that allows selection of text files with extensions .TXT and .DOC, and the other labeled All files that allows selection of all files:
Text Files:*.TXT;*.DOC,All files:*
So it seems CS2 won't set capacity to allow multiple selecting files
So you have to use a workaround.
Folder.getFiles() with a indd selection could do the trick but it implies that it will get ALL the files available and not the one the user may only want...
BUT you know what ? Why don't you just giv a try and maybe in CS2 multi opening will be allowed with the File.openDialog method without any need to set anything ?
For more precise informations, I give my place to specialists :-)
Norbert D'souza
2008-08-11 00:44:55 UTC
Permalink
Hi Loic,

You are right. Page 540 of the CS2 scripting guide does say:

"A file or files to be preselected when the dialog opens:"

However myFile=File.openDialog("Pick me","Files : *.indd", true);

Doesn't aqllow multiple selections.

So is the CS2 Scripting guide wrong or am I doing something wrong?

Regards
Norbert
loic_aigon
2008-08-11 20:17:22 UTC
Permalink
Well effectively the formulation of the explanation let think that you can select multiple files but the command doesn't.
Weird, either the explanation is false, either we misunderstood a point.
Olav will be welcome to clear that stuff !
Norbert D'souza
2008-08-12 07:18:55 UTC
Permalink
How does one get in touch with Olav to rea a particlar thread? Or does he read all thats posted here??
loic_aigon
2008-08-12 08:08:53 UTC
Permalink
okvern at adobe.com at the last resort :-)
Norbert D'souza
2008-08-13 04:28:32 UTC
Permalink
Hi Loic,

I normally don't send private emails regarding forum posts but maybe this time I will.

However, what other options do I have before I email Olav?

Regards
Norbert
loic_aigon
2008-08-13 06:24:09 UTC
Permalink
What about posting a new topic called "CS2 openDialog problem" ?
It's true that if Olav can answer to your problem, it's better that anyone can enjoy it.
Loic
D***@adobeforums.com
2008-08-17 13:02:17 UTC
Permalink
I've just realized why it is not at all odd that (as I said in message 9) "...no matter what you do, application files are always active..."

The reason is that they are returned to ExtendScript as folders, not files, so my previous code that explicitly tested for files with a .app extension was on the right track but in the wrong place. If you want to exclude applications, you need to add logic to the folder detection code, returning false if the folder name ends in .app.

You can check this by running:

#target indesign
alert(app.fullName.constructor.name)

It displays an alert that says Folder.

Dave
S***@adobeforums.com
2008-08-17 13:17:08 UTC
Permalink
Post by D***@adobeforums.com
they are returned to ExtendScript as folders, not files
Presumably only if they are packaged as bundles; these days that's pretty
much all apps, but older ones might not be. And some "files" are also
packages and therefore presumably returned as folders, although they're much
rarer.
--
Shane Stanley <***@myriad-com.com.au>
Loading...