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

相关推荐
亿元程序员13 分钟前
为什么现在 AI 这么发达了,还要坚持手搓教程?
前端
三小河1 小时前
在 Codex 桌面端接入 DeepSeek 模型(CC Switch 代理中转)
前端·javascript·人工智能
云边有个稻草人1 小时前
飞牛 NAS 远程访问实战:星空组网连接 Mac 与安卓,从 Compose 部署到 5G 验证
android·5g·macos
CoderYanger1 小时前
前端基础——JavaScript(WebAPI)代码案例
java·开发语言·前端·javascript·css·前端框架·html5
聚美智数1 小时前
手机号归属地-手机号归属地查询-手机归属地-运营商归属地
android·智能手机
恋猫de小郭1 小时前
Shopify 从 React Native 回到 Swift/Kotlin,但是你以为有手就行??
android·前端·ios
菠萝加点糖1 小时前
Android ChipGroup 使用说明
android
BillKu2 小时前
Element Plus 的 el-tab-pane:lazy 的说明
前端·javascript·vue.js
爱勇宝2 小时前
《道德经》第 11 章:真正有用的,常常是你没写出来的那部分
前端·后端·产品
jearry2 小时前
WebView2 原生拖放的桥接之道:拆解 yyzTools 的 drop-zone.js
前端·c++