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

相关推荐
薛端阳2 小时前
OpenClaw的架构优化思路杂想
前端
hi大雄2 小时前
我的 2025 — 名为《开始的勇气》🌱
前端·年终总结
OpenTiny社区2 小时前
TinyRobot:基于 OpenTiny Design 的企业级 AI 交互组件框架
前端·vue.js·ai编程
用户3153247795452 小时前
Tailwind CSS 学习手册
前端·css
踩着两条虫2 小时前
AI 驱动的 Vue3 应用开发平台 深入探究(三):核心概念之引擎架构与生命周期
前端·vue.js·ai编程
发际线向北2 小时前
0x00 Android 渲染机制解析
前端
没有了遇见2 小时前
Android(Coil,Glide)大量图片加载缓存清理问题(二 Coil处理)
android
_Eleven2 小时前
Tiptap 完全使用指南
前端·vue.js·github
小蜜蜂dry2 小时前
nestjs学习 - 中间件(Middleware)
前端·nestjs