如何在插入 USB 时自动在 Mac OS X 上打开 finder?

How to open finder on Mac OS X automatically when USB plugged in?

超级简单的问题,但我找不到答案。

我希望 Finder 在插入 USB 驱动器时打开安装的磁盘...如何?

您应该可以通过将 Folder Action 添加到文件夹 Volumes 来完成此操作,该文件夹是安装外部磁盘的地方。 AFAIK,您只能在 Finder 中执行此操作,并且 /Volumes 文件夹在 Finder 中设置为不可见 - 谢谢,Apple。

因此,首先要使 /Volumes 文件夹对 Finder 可见,方法是启动终端和 运行

sudo SetFile -a v /Volumes

现在,启动 Finder 和 select 您的系统驱动器,然后在左窗格中 Macintosh HD。您现在应该看到

  • 应用程序
  • 图书馆
  • 系统
  • 用户
  • 数量

右键单击 Volumes 文件夹并转到 Setup Folder Actions 并附加 add - new item 脚本。然后你可以随意使用它来做任何你想让 Finder 在插入磁盘时做的事情。

谢谢@mark-setchell

我的 /Volumes 文件夹得到了这个 Apple 脚本:

on adding folder items to this_folder after receiving added_items
    try
        tell application "Finder"
            --open window and activate finder 
            activate
            --open the USB
            open added_items
        end tell
    end try
end adding folder items to

因此,每次 /Volumes 文件夹中出现一些新项目时,Finder 都会打开 window 并选择该项目。

此解决方案在打开查找器之前有一些延迟(5-10 秒)。我想文件夹操作就是这样工作的...

添加到@MarkSetchell 的回答中,为了使/Volumes 文件夹可见,我不得不使用sudo chflags nohidden /Volumes。然而,使此文件夹可见(并且暂时,这可能是首选)的更简单方法是使用组合键:

Cmd (⌘) + Shift + .

(我的上下文菜单项也是 Services > Folder Actions Setup

为了让别人省心,这些脚本保存的文件夹是/Library/Scripts/Folder Action Scripts(说来惭愧,找了好几个小时)

使用终端和 sudo 在此处创建一个新文件,粘贴上面的脚本,并将其添加到文件夹操作设置中。它就像一个魅力(至少对我而言)。