Raycast 实现 scrcpy 的快捷显示隐藏
Raycast 支持对 app 设置快捷键以动态显示/隐藏该 App

日常使用 scrcpy 比较多,有没有办法让 scrcpy 的窗口也支持快捷键显隐呢?
答案是可以的,我们可以通过创建脚本,并给脚本设置快捷来实现该操作:
- 在 Raycast script command 目录下创建脚本,命名为 toggle-scrcpy.sh

shell
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Toggle Scrcpy
# @raycast.mode silent
APP="scrcpy"
# 如果没启动 → 启动并拉到前台
if ! pgrep -x "$APP" > /dev/null; then
scrcpy &
# 等待窗口创建
sleep 1
osascript <<EOF
tell application "System Events"
tell process "$APP"
set frontmost to true
end tell
end tell
EOF
exit 0
fi
# 获取是否在前台
frontmost=$(osascript <<EOF
tell application "System Events"
tell process "$APP"
return frontmost
end tell
end tell
EOF
)
# 如果在前台 → 隐藏
if [ "$frontmost" = "true" ]; then
osascript <<EOF
tell application "System Events"
tell process "$APP"
set visible to false
end tell
end tell
EOF
# 如果在后台 → 拉到前台
else
osascript <<EOF
tell application "System Events"
tell process "$APP"
set visible to true
set frontmost to true
end tell
end tell
EOF
fi
- 执行
chmod +x toggle-scrcpy.sh基于权限 - 执行
Reload Script Directories命令刷新脚本

- 给脚本设置快捷键

enjoy it 🎉
