最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论