Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change Default Path of File Open Dialog?

I'm writing a script that allows me to do some basic imposition within InDesign CS3, and one of my tasks is to open a dialog allowing the user to select a file to place. I'm currently doing this with:

var file = File.openDialog("Choose a File:");

The problem seems to be when navigating to a network drive through a shortcut. For some reason, the dialog sees it as a file, and returns that path from the dialog, rather than navigating to the folder location. I'm assuming this is just a bug in the dialog, and my initial thought was to check to see if the returned file has a correct extension, and if not, display the dialog again, opened to the returned path location. However, I can't seem to find a way to change where it opens by default; openDlg() only has parameters for String prompt, var filter, and boolean multiselect. I'm not familiar with Javascript, so I don't know whether this is something with a general solution, or particular to InDesign.

EDIT: If anyone's interested, here's the final code I used to get around the problem:

var path = new File("~/desktop");
var file = path.openDlg("Choose File:");
while (file.alias) {
    file = file.resolve().openDlg("Choose File:");
}

Basically, checks if it's a shortcut (alias), and if so, resolves the target and displays the dialog again. Kind of a hackish way to go about it, but it works just fine. May want to add some null handling in there, too, though, as if the dialog is cancelled, null is returned.

like image 945
Kevin Coppock Avatar asked Nov 14 '22 03:11

Kevin Coppock


1 Answers

Have you tried getting a handle to a file/directory that you want by default and calling fileHandle.openDlg() ?

http://forums.adobe.com/message/1109421#1109421

like image 142
Juan Mendes Avatar answered Dec 20 '22 00:12

Juan Mendes