新建一个 Workflow

用关键字或者热键来运行下面的 AppleScript 脚本。
别忘了修改代码中的 Airpods 名。

on alfred_script(q)
  activate application "SystemUIServer"
  tell application "System Events"
    tell process "SystemUIServer"
      
    set btMenu to (menu bar item 1 of menu bar 1 whose description contains "volume")
    tell btMenu
      click
      set btAirpods to (menu item "Zexi’s AirPods" of menu 1)
      if exists btAirpods then
        click btAirpods
        return "Switching..."
      end if
    end tell

    end tell
  end tell
end alfred_script

这里还有一个图标

airpods