状态:已完结。
InputAutoSwitcher 是一个轻量的 macOS 菜单栏工具。它会在前台应用切换时,根据你配置的规则自动切换输入法,例如在代码编辑器中使用英文,在聊天或文档应用中使用中文输入法。
仓库内已包含本机生成的可运行版本:
下载后解压,双击 InputAutoSwitcher.app 即可运行。首次运行如果遇到 macOS 安全提示,可在“系统设置 > 隐私与安全性”中允许打开。
- 监听前台应用变化,并按应用自动切换输入法
- 在设置页中选择“应用 + 输入法”,无需手动填写 Source ID
- 支持“按当前应用新增”快速创建规则
- 支持全局锁定输入法
- 支持开机自启动
- 菜单栏动态图标会显示当前 App 与输入法状态
- 使用
UserDefaults本地持久化配置 - 已接入 macOS 应用图标:
Resources/InputAutoSwitcher.icns
- 运行
InputAutoSwitcher.app - 点击菜单栏图标
输入法切换 - 打开设置
- 为不同应用选择对应输入法
- 切换前台应用后,工具会自动应用匹配规则
常见输入法 Source ID:
com.apple.keylayout.ABC:英文 ABCcom.apple.inputmethod.SCIM.ITABC:简体拼音
实际可选输入法以当前 macOS 系统已安装的输入法为准。
要求:
- macOS 13 或更新版本
- Xcode / Swift 5.9 或更新版本
编译:
swift build打包 .app 和 .app.zip:
./scripts/package_app.sh打包产物会生成在:
dist/InputAutoSwitcher.appdist/InputAutoSwitcher.app.zip
.
├── Package.swift
├── README.md
├── Resources/
│ └── InputAutoSwitcher.icns
├── Sources/
│ └── InputAutoSwitcher/
│ ├── AppDiscoveryService.swift
│ ├── InputAutoSwitcherApp.swift
│ ├── InputSwitcherService.swift
│ ├── LaunchAtLoginManager.swift
│ ├── MappingStore.swift
│ ├── MenuBarIconRenderer.swift
│ ├── Models.swift
│ └── Views.swift
├── dist/
│ └── InputAutoSwitcher.app.zip
└── scripts/
└── package_app.sh
仓库包含 macOS 构建工作流:
.github/workflows/build-macos-app.yml
触发方式:
- 推送到
main - 在 GitHub Actions 页面手动触发
Build macOS App
构建完成后,可在该次运行的 Artifacts 中下载:
InputAutoSwitcher-macos-app