Applescript 如何使用Apple JXA装载卷并打开文件夹

Applescript 如何使用Apple JXA装载卷并打开文件夹,applescript,javascript-automation,Applescript,Javascript Automation,我想挂载一个卷,然后立即打开一个特定路径的查找窗口,但我在从Apple脚本转换到JXA时遇到了问题 我想要类似这样的JXA等价物: tell application "Finder" if not (disk "Airport Time Capsule" exists) then mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local" end if open "/Volume

我想挂载一个卷,然后立即打开一个特定路径的查找窗口,但我在从Apple脚本转换到JXA时遇到了问题

我想要类似这样的JXA等价物:

tell application "Finder"
    if not (disk "Airport Time Capsule" exists) then
        mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
    end if
    open "/Volumes/Airport Time Capsule"
end tell
我试过一些方法,但似乎都不管用。JXA的完整文档不存在

var finder = Application('Finder');
finder.mount('afp://.....'); // doesn't work
finder.mount.volume('afp://.....'); // doesn't work
finder.mountVolume('afp://.....'); // doesn't work

下面的代码应该大致模拟您的AppleScript。它检查具有指定名称(“机场时间胶囊”)的磁盘是否已安装,如果已安装,则打开该磁盘,或者使用
openLocation
功能(需要
standardAdditions
)连接到时间胶囊:


实际上,我不得不在我的笔记本电脑上将“机场时间胶囊”改为“手机备份”,因此如果上述代码不起作用,您可以尝试一下。

以下代码应该大致模拟您的AppleScript。它检查具有指定名称(“机场时间胶囊”)的磁盘是否已安装,如果已安装,则打开该磁盘,或者使用
openLocation
功能(需要
standardAdditions
)连接到时间胶囊:


实际上,我不得不在笔记本电脑上将“机场时间胶囊”改为“手机备份”,因此,如果上述代码不起作用,您可以尝试一下。

效果很好,感谢您,并对最终测试的延迟表示歉意。我以机场时间胶囊为例,但实际上它不是我需要打开的文件夹。由于隐私原因,这是我无法发布的工作内容。工作完美,感谢您,并对最终测试的延迟表示抱歉。我以机场时间胶囊为例,但实际上它不是我需要打开的文件夹。这是因为工作原因,因为隐私问题,我不能发布。
var finder = Application('Finder')
finder.includeStandardAdditions = true
var disks = finder.disks.where({name: 'AirPort Time Capsule'})
if (disks.length > 0) {
    finder.open(disk[0])
} else {
    finder.openLocation('afp://[your-time-capsule].local')
}