我正在尝试做一件非常简单的事情 - 使用 OS X Yosemite 引入的 JavaScript for Automation 移动(或复制)文件。
到目前为止我有这样的东西。
finder = Application("Finder")
finder.move(Path("/Users/user/Source/file.pdf"), {
to: Path("/Users/user/Destination/file.pdf"),
replacing: true
})
结果并不理想。
Error -1728: Can't get object.
当然,我可以使用像 doShellScript("mv source destination")
这样的东西,但 Finder + JAX 解决方案似乎更好。
最佳答案
Finder 的 move
和 duplicate
操作与 JXA Path
对象配合得很好。您的代码失败的原因是,当您提供文件的路径时,这些操作期望的to
参数是文件夹的路径。这将起作用:
finder = Application("Finder")
finder.move(Path("/Users/user/Source/file.pdf"), {
to: Path("/Users/user/Destination/"),
replacing: true
})
关于macos - JXA : move or duplicate files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29241422/