macos - JXA : move or duplicate files

标签 macos applescript osx-yosemite javascript-automation

我正在尝试做一件非常简单的事情 - 使用 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 的 moveduplicate 操作与 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/

相关文章:

racket - DrRacket 在 OS X 10.10 (Yosemite) 上崩溃?

jboss - 为什么我无法终止我的JBoss进程?

objective-c - 有没有办法更新 launchd overrides.plist 上的 SMLoginItemBookmarks 数据

macos - 网络链接调节器在 macOS Sierra 上不起作用

csv - 将 CSV 文件导入 iCal

linux - 从 USB 启动 applescript?

macos - 在OSX El Capitan中Visual Studio Code安装失败

excel - 在 VBA for Mac 中写入具有长名称的文件

python - 从 VBA 单词运行 python 并返回一个值

macos - 使用 OS X 10.10 Yosemite Beta 使用 Homebrew 重新安装 MongoDB 时遇到问题