如何更改文件打开对话框的默认路径?
我正在编写一个脚本,允许我在 InDesign CS3 中进行一些基本拼版,我的任务之一是打开一个对话框,允许用户选择要放置的文件。我目前正在这样做:
var file = File.openDialog("Choose a File:");
问题似乎是通过快捷方式导航到网络驱动器时。由于某种原因,对话框将其视为文件,并从对话框返回该路径,而不是导航到文件夹位置。我假设这只是对话框中的一个错误,我最初的想法是检查返回的文件是否具有正确的扩展名,如果没有,则再次显示对话框,打开到返回的路径位置。但是,我似乎找不到更改默认打开位置的方法; openDlg()
仅具有字符串提示
、var filter
和布尔多选
的参数。我对 Javascript 不熟悉,所以我不知道这是否是通用解决方案,还是 InDesign 特有的解决方案。
编辑:如果有人感兴趣,这是我用来解决问题的最终代码:
var path = new File("~/desktop");
var file = path.openDlg("Choose File:");
while (file.alias) {
file = file.resolve().openDlg("Choose File:");
}
基本上,检查它是否是快捷方式(别名),如果是,则解析目标并再次显示对话框。有点黑客的方法,但效果很好。不过,可能还想在其中添加一些 null 处理,就像取消对话框一样,返回 null。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过默认获取所需文件/目录的句柄并调用 fileHandle.openDlg() ?
http://forums.adobe.com/message/1109421#1109421
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