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

相关推荐
Csvn1 小时前
Monorepo 迁移血泪史:从 Multi-Repo 到 Turborepo,这 3 个坑我帮你踩完了
前端
星栈1 小时前
Dioxus 多页面怎么做:`dioxus-router`、嵌套路由、`Outlet` 和页面组织,一篇给你讲顺
前端·rust·前端框架
badhope1 小时前
做了几年安卓开发,这些坑我帮你踩过了
android·android studio
用户987409238871 小时前
用 Remotion + edge-tts 打造中文教学视频全自动流水线
前端
风骏时光牛马1 小时前
Less前端工程化实战:变量混合器与项目样式分层落地
前端
假如让我当三天老蒯1 小时前
Options API(选项式 API) 和 Composition API(组合式 API)
前端·vue.js·面试
SameX1 小时前
iOS 独立开发实践:用 MapKit + 像素渲染实现 Citywalk 轨迹地图 App「雁过留痕」
前端
skyey2 小时前
页面加载时,深色模式闪白的问题解决
前端
IT_陈寒2 小时前
Java 并行流把我坑惨了,这6小时加班值了
前端·人工智能·后端
anOnion11 小时前
构建无障碍组件之Menu Button pattern
前端·html·交互设计