【每日一技】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 🎉

相关推荐
Moment11 分钟前
面试官:如果产品经理给你多个需求,怎么让AI去完成❓❓❓
前端·后端·面试
每天吃饭的羊13 分钟前
JSONP
前端
gogoing19 分钟前
ESLint 配置字段说明
前端·javascript
gogoing30 分钟前
CSS 属性值计算过程(Computed Value)
前端·css
gogoing31 分钟前
webpack 的性能优化
前端·javascript
桃花键神35 分钟前
Bright Data Web Scraping指南 2026: 使用 MCP + Dify 自动采集海外社交媒体数据
大数据·前端·人工智能
gogoing38 分钟前
await fetch() 的两阶段设计
前端·javascript
gogoing44 分钟前
前端首屏加载优化
前端·javascript
gogoing1 小时前
重排与重绘
前端·javascript
阿巴斯甜1 小时前
Kotlin 协程 Coroutine
android