javascript - How to Change Default Path of File Open Dialog? - Stack Overflow

I'm writing a script that allows me to do some basic imposition within InDesign CS3, and one of my

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.

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.

Share edited Jan 28, 2011 at 19:05 Kevin Coppock asked Jan 28, 2011 at 17:55 Kevin CoppockKevin Coppock 135k45 gold badges268 silver badges277 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 1

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745046010a4608101.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信