【发布时间】:2018-11-21 23:51:42
【问题描述】:
在一个 applescript 中,我收到一个必须打开的文件路径。
文件路径的格式为“/Users/xxx/my/file/to/open.xyz”。
我想用默认程序打开它。如果是AVI,我需要用视频程序打开,如果是xls,用excel,...
我尝试了几件事但没有成功:
--dstfile contains the previous path
tell application "Finder"
activate
open document dstfile
end tell
-->我收到错误 1728,告诉我他无法获取文档
tell application "Finder"
activate
open document file dstfile
end tell
-->这里也一样
tell application "Finder"
activate
open document POSIX file dstfile
end tell
-->这里也一样
我确定该文件存在,因为我在执行此代码之前执行了此操作:
if not (exists dstfile) then
display dialog "File isn't existing"
end if
我不能使用 to of... 的合成器 open.xyz,因为我收到了这个作为参数。
请帮助我绝望:'(
答案:根据答案,我得出以下结论:
set command to "open " & quoted form of dsturl
do shell script command
【问题讨论】:
-
我强烈建议您避免使用此解决方案。它很脆弱,速度较慢,而且完全没有必要。使用@kopischke 的答案:stackoverflow.com/a/10132641/754997
标签: scripting applescript