【发布时间】:2015-07-20 04:36:14
【问题描述】:
这似乎是一件很容易做到的事情,我很惊讶解决方案仍然无法解决。
我正在尝试存储“选择文件”对话框打开的最后一个文件夹。我想将该文件夹的位置存储在文本文件中。
我想让我的“选择文件”对话框始终打开到最后使用的文件夹。
我已经完成了很多脚本,但是有一件奇怪的事情一直在逃避我。
看看我的脚本...
set Shows to paragraphs of (read POSIX file "/Users/lowken/Documents/config.txt")
set strPathFromConfig to item 1 of Shows as string
set strPathFromConfig to ((characters 3 thru -1 of strPathFromConfig) as string)
display dialog strPathFromConfig
set strPath to (path to home folder as text) & strPathFromConfig
display dialog strPath
choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} default location alias strPath
脚本读取我的配置文本文件,其中包含一行和一串“文档”。
我修剪了一些前导的乱码,并显示一个带有“文档”结果的对话框。
然后我使用配置文件中的值设置 strPath。
我显示新值是否是我系统上的有效位置。
接下来我尝试打开对话框,我收到一条错误消息“文件别名 Macintosh HD:Users:lowken:Documents of was not found.
让我们更改脚本,而不是使用从 config.txt 文件中提取的值,我只需在脚本中设置一个字符串变量。
set Shows to paragraphs of (read POSIX file "/Users/lowken/Documents/config.txt")
set strPathFromConfig to item 1 of Shows as string
set strPathFromConfig to ((characters 3 thru -1 of strPathFromConfig) as string)
display dialog strPathFromConfig
set strTemp to "Documents"
set strPath to (path to home folder as text) & strTemp
display dialog strPath
choose file with prompt "Please choose a file:" of type {"XLSX", "APPL"} default location alias strPath
现在可以了。 AppleScript 似乎不想使用从 config.txt 文件中查找的值。
我做错了什么?我尝试投射到别名,我尝试了系统上的不同位置。
在我看来,不知何故从文本文件中查找的值不是字符串数据类型。
有什么想法吗?
附:
我在 2012 年中期的 MacBook Pro 上运行 OS X Yosemite 10.10.4。
【问题讨论】:
标签: applescript