🧪 One-Click Automation Scripts (Beta)
⚠️ Experimental Feature
The following scripts aim to automate environment installation and configuration via the command line. Due to differences in system environments (macOS/Windows versions, network environments), these scripts have not undergone large-scale compatibility testing. Please read the code before use and ensure you understand what the script is about to execute.
We have prepared Shell (macOS) and PowerShell (Windows) scripts for advanced users to complete the following tasks with one click:
- ✅ Auto-install DeskFlow, LocalSend, BlackHole/SonoBus
- ✅ Auto-fix macOS app signature (
xattr) - ✅ Auto-generate configuration file with key mapping
- ✅ Auto-guide firewall or system permission settings
🍎 macOS One-Click Setup Script
This script automatically detects Homebrew, installs software, generates configuration files, and opens Accessibility settings.
Usage
- Open Terminal.
- Create a script file and paste the code:bash
nano setup_mac.sh # Paste the code below, then press Ctrl+O to save, Ctrl+X to exit - Grant execution permission and run:bash
chmod +x setup_mac.sh ./setup_mac.sh
Script Code (setup_deskbridge.sh)
Click to expand Shell script code
#!/bin/bash
# ==========================================
# 🌉 Win-Mac DeskBridge 一键配置脚本
# 作者: AGI-FBHC Lab
# 描述: 自动安装 DeskFlow/BlackHole,生成键位映射配置,引导权限设置。
# ==========================================
# 定义颜色,让输出更好看
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE} 🌉 Win-Mac DeskBridge Setup v1.0 ${NC}"
echo -e "${BLUE}=========================================${NC}"
# --- 1. 检查并安装 Homebrew ---
echo -e "\n${YELLOW}[1/5] 检查环境...${NC}"
if ! command -v brew &> /dev/null; then
echo -e "${RED}未检测到 Homebrew。${NC}"
echo "请先安装 Homebrew: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
exit 1
else
echo -e "${GREEN}Homebrew 已安装。${NC}"
fi
# --- 2. 安装 DeskFlow 和 BlackHole ---
echo -e "\n${YELLOW}[2/5] 安装核心组件...${NC}"
# 安装 DeskFlow
if brew list deskflow &> /dev/null; then
echo -e "DeskFlow 已安装,跳过。"
else
echo "正在安装 DeskFlow..."
brew tap deskflow/homebrew-tap
brew install deskflow
fi
# 安装 BlackHole (音频驱动)
if brew list blackhole-2ch &> /dev/null; then
echo -e "BlackHole 已安装,跳过。"
else
echo "正在安装 BlackHole 2ch..."
brew install blackhole-2ch
echo -e "${GREEN}音频驱动安装完成(可能需要重启后生效)。${NC}"
fi
# --- 3. 自动修复应用权限 (xattr) ---
echo -e "\n${YELLOW}[3/5] 修复 DeskFlow 签名权限...${NC}"
APP_PATH="/Applications/DeskFlow.app"
if [ -d "$APP_PATH" ]; then
sudo xattr -cr "$APP_PATH"
echo -e "${GREEN}已移除隔离属性,防止'应用已损坏'报错。${NC}"
else
echo -e "${RED}警告: 未找到 $APP_PATH,请确认安装路径。${NC}"
fi
# --- 4. 生成完美配置文件 (.conf) ---
# 这是最爽的一步:直接生成带键位映射的配置,免去 GUI 手动配置的痛苦
echo -e "\n${YELLOW}[4/5] 生成智能配置文件...${NC}"
CONFIG_DIR="$HOME/Library/Deskflow"
CONFIG_FILE="$CONFIG_DIR/deskflow.conf"
mkdir -p "$CONFIG_DIR"
# 获取当前用户名作为主机名
MAC_HOSTNAME=$(scutil --get LocalHostName)
WIN_HOSTNAME="win-client" # 默认 Windows 名字
echo "正在生成配置文件到: $CONFIG_FILE"
cat > "$CONFIG_FILE" <<EOF
section: screens
$MAC_HOSTNAME:
# Mac 作为服务端
$WIN_HOSTNAME:
# Windows 作为客户端
# 键位映射魔法:把 Win 的 Ctrl 变成 Command (Super),把 Win 的 Win键 变成 Ctrl
ctrl = super
super = ctrl
end
section: aliases
end
section: links
$MAC_HOSTNAME:
# Windows 在 Mac 的右边 (如果不合适请手动改为 left)
right = $WIN_HOSTNAME
$WIN_HOSTNAME:
left = $MAC_HOSTNAME
end
section: options
relativeMouseMoves = false
screenSaverSync = false
win32KeepForeground = false
clipboardSharing = true
switchCorners = none
switchCornerSize = 0
end
EOF
echo -e "${GREEN}配置文件已生成!${NC}"
echo -e "默认设置:Mac 为主控,Windows 名为 '${YELLOW}$WIN_HOSTNAME${NC}',位于 Mac 右侧。"
echo -e "已应用键位映射:${BLUE}Ctrl -> Command, Win -> Ctrl${NC}"
# --- 5. 引导权限设置 ---
echo -e "\n${YELLOW}[5/5] 引导系统权限设置...${NC}"
echo -e "${RED}注意:由于 macOS 安全限制,脚本无法自动勾选权限。${NC}"
echo -e "即将打开系统设置,请手动开启 DeskFlow 的 ${YELLOW}[辅助功能]${NC} 和 ${YELLOW}[输入监控]${NC} 权限。"
read -p "按回车键打开系统设置..."
# 打开“隐私与安全性”面板
open "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
echo -e "\n${GREEN}=== ✅ 配置脚本执行完毕 ===${NC}"
echo -e "下一步操作:"
echo -e "1. 在弹出的设置窗口中,允许 DeskFlow 控制电脑。"
echo -e "2. 打开 DeskFlow 软件。"
echo -e "3. 点击菜单栏 'File' -> 'Save Configuration As' -> 选择刚才生成的 $CONFIG_FILE (可选)"
echo -e " 或者直接在界面上把 Screen Name 改为 ${YELLOW}$MAC_HOSTNAME${NC} 即可。"
echo -e "4. 在 Windows 端 DeskFlow 输入 Screen Name: ${YELLOW}$WIN_HOSTNAME${NC}"(Note: If the code above does not display, please visit the repository directory /scripts/setup_deskbridge.sh to view it)
🪟 Windows One-Click Setup Script
This script uses Winget and GitHub API to auto-install software, configure firewall rules, and guide audio settings.
Usage
- Create a new text document on the desktop and rename it to
setup_win.ps1(Note the.ps1extension). - Right-click the file -> Edit, paste the code below and save.
- Right-click the file -> Select "Run with PowerShell".
- If prompted that scripts cannot be run, open PowerShell as Administrator and enter:powershell
Set-ExecutionPolicy RemoteSigned # Enter Y to confirm
Script Code (setup_deskbridge.ps1)
Click to expand PowerShell script code
<#
.SYNOPSIS
🌉 Win-Mac DeskBridge Windows 端一键配置脚本
.DESCRIPTION
自动安装 DeskFlow/LocalSend/SonoBus,配置防火墙规则,引导音频和SMB设置。
.NOTES
需要以管理员权限运行。
#>
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " 🌉 Win-Mac DeskBridge Windows Setup " -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
# --- 检查管理员权限 ---
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "请以管理员身份运行此脚本!(右键 -> 使用 PowerShell 运行)"
Start-Sleep -Seconds 3
Exit
}
# --- 1. 使用 Winget 安装常用工具 (LocalSend, SonoBus) ---
Write-Host "`n[1/4] 正在检查并安装基础软件 (Winget)..." -ForegroundColor Yellow
$tools = @{
"LocalSend" = "LocalSend.LocalSend";
"SonoBus" = "SonoBus.SonoBus"
}
foreach ($name in $tools.Keys) {
$id = $tools[$name]
Write-Host "正在检查 $name..."
winget list -e $id | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "正在安装 $name..." -ForegroundColor Green
winget install --id $id -e --source winget --accept-package-agreements --accept-source-agreements
} else {
Write-Host "$name 已安装,跳过。" -ForegroundColor Gray
}
}
# --- 2. 手动下载并安装 DeskFlow (GitHub Releases) ---
# 因为 DeskFlow 较新,Winget 可能未收录,我们直接从 GitHub 抓取最新 msi
Write-Host "`n[2/4] 正在获取 DeskFlow 最新版本..." -ForegroundColor Yellow
$repo = "deskflow/deskflow"
$releasesUrl = "https://api.github.com/repos/$repo/releases/latest"
try {
# 获取最新版本的下载链接 (查找 windows-x86_64.msi)
$release = Invoke-RestMethod -Uri $releasesUrl
$asset = $release.assets | Where-Object { $_.name -match "windows-x86_64.msi$" } | Select-Object -First 1
if ($asset) {
$downloadUrl = $asset.browser_download_url
$outFile = "$env:TEMP\deskflow_installer.msi"
Write-Host "正在下载: $($asset.name)" -ForegroundColor Green
Invoke-WebRequest -Uri $downloadUrl -OutFile $outFile
Write-Host "正在静默安装 DeskFlow..." -ForegroundColor Green
# 启动 MSI 安装
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$outFile`" /quiet /norestart" -Wait
Write-Host "DeskFlow 安装完成!" -ForegroundColor Green
} else {
Write-Error "未找到 Windows 安装包,请手动下载。"
}
} catch {
Write-Error "下载失败: $_"
Write-Warning "请手动访问 https://github.com/deskflow/deskflow/releases 下载安装。"
}
# --- 3. 配置防火墙 (至关重要) ---
Write-Host "`n[3/4] 配置防火墙规则..." -ForegroundColor Yellow
$progPath = "C:\Program Files\DeskFlow\deskflow.exe" # 默认路径,根据实际情况可能需要调整
if (Test-Path $progPath) {
# 删除旧规则(如果有)
Remove-NetFirewallRule -DisplayName "DeskFlow Allowed" -ErrorAction SilentlyContinue
# 添加新规则:允许 DeskFlow 在专用和公用网络通信
New-NetFirewallRule -DisplayName "DeskFlow Allowed" -Direction Inbound -Program $progPath -Action Allow -Profile Any | Out-Null
Write-Host "防火墙规则已添加:允许 DeskFlow 通信。" -ForegroundColor Green
} else {
Write-Warning "未找到 DeskFlow 主程序,跳过防火墙配置。请手动允许 deskflow.exe 通过防火墙。"
}
# --- 4. 引导后续设置 ---
Write-Host "`n[4/4] 正在打开系统设置面板..." -ForegroundColor Yellow
# 打开声音录制面板 (方便设置 Line-In 侦听)
Write-Host "-> 打开声音录制面板 (请找到 '线路输入' -> 属性 -> 侦听)"
Start-Process "mmsys.cpl" -ArgumentList ",1"
# 打开映射网络驱动器向导
Write-Host "-> 打开映射网络驱动器向导 (请输入 Mac 的 SMB 地址)"
# 这是一个黑科技命令,直接唤起“映射网络驱动器”窗口
$objShell = New-Object -ComObject Shell.Application
$objShell.FileRun()
#以此提示用户输入 \\IP
Write-Host "`n=========================================" -ForegroundColor Green
Write-Host " ✅ Windows 端配置脚本执行完毕" -ForegroundColor Green
Write-Host "========================================="
Write-Host "下一步:"
Write-Host "1. 在刚才弹出的声音窗口中配置音频侦听。"
Write-Host "2. 打开桌面的 DeskFlow 图标,填入 Client 配置。"
Write-Host "3. 按 Win+R 输入 \\Mac-IP 访问文件。"
Start-Sleep -Seconds 5(Note: If the code above does not display, please visit the repository directory /scripts/setup_deskbridge.ps1 to view it)