【每日一技】Raycast 实现 scrcpy 的快捷显示隐藏

Raycast 实现 scrcpy 的快捷显示隐藏

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

日常使用 scrcpy 比较多,有没有办法让 scrcpy 的窗口也支持快捷键显隐呢?

答案是可以的,我们可以通过创建脚本,并给脚本设置快捷来实现该操作:

  1. 在 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
  1. 执行 chmod +x toggle-scrcpy.sh 基于权限
  2. 执行 Reload Script Directories 命令刷新脚本
  1. 给脚本设置快捷键

enjoy it 🎉

相关推荐
AiMan9 分钟前
腾讯ima还是不可以导出左侧所有对话,只能单条导出,方法不对吗
前端
去伪存真12 分钟前
并发量一高就装死?Agent 全链路“防猝死”手册
前端·agent
Moment14 分钟前
AI 编程时代,聊聊我的 Mac mini 双屏桌面
前端·后端
AiMan25 分钟前
先确认能不能一次把Microsofat Copilot所有内容打包一个文件导出
前端
总要学点什么29 分钟前
第97篇:三维数据加载-城市建筑白模自定义着色器——让一条光带沿高度扫上去,快慢却由帧率说了算
前端·gis·webgl·cesium·着色器·空间分析·白模
木头左36 分钟前
【架构设计】教育类 App 服务端化改造:AI 上移、题库分层与个人题库归属
android·架构设计·系统设计·后端开发·数据库设计
上海懒图科技1 小时前
工厂厂区电子地图定位导航:厂区人车精准定位,安全合规双保障
前端·arcgis·vue
墨狂之逸才1 小时前
USB 的 HOST 和 DEVICE 到底有什么区别?ADB 调试应该选哪个?
android
西安小哥1 小时前
端侧跑大模型,真正的门槛不在参数量:一次 596 秒到 10 秒的压缩路径复盘
前端·人工智能
陈随易2 小时前
Cloudflare 出钱,Vite 团队挑人,44 个维护者分 30 万美元
前端·后端·程序员