Raycast 脚本命令模板
快速启动类
打开项目
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Open Project
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 📁
# @raycast.argument1 { "type": "dropdown", "placeholder": "Select Project", "data": [{"title": "Project A", "value": "project-a"}, {"title": "Project B", "value": "project-b"}] }
# @raycast.packageName Development
PROJECT_DIR="$HOME/Developer"
cd "$PROJECT_DIR/$1" && code .
启动开发环境
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Start Dev Environment
# @raycast.mode fullOutput
# @raycast.icon 🚀
PROJECT=$(basename "$PWD")
echo "🚀 Starting $PROJECT..."
# 启动服务
if [ -f "docker-compose.yml" ]; then
docker-compose up -d
echo "✅ Docker containers started"
fi
if [ -f "package.json" ]; then
npm install
npm run dev &
echo "✅ Dev server starting..."
fi
# 打开浏览器
sleep 2
open "http://localhost:3000"
echo "✅ Environment ready!"
开发工具类
Git状态检查
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Git Status
# @raycast.mode fullOutput
# @raycast.icon 🔍
if [ ! -d .git ]; then
echo "❌ Not a git repository"
exit 1
fi
echo "📊 Git Status"
echo "─────────────────"
git status -sb
echo ""
echo "📝 Recent Commits"
echo "─────────────────"
git log --oneline -5
echo ""
echo "🔀 Branches"
echo "─────────────────"
git branch -v
AI Commit
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title AI Commit
# @raycast.mode fullOutput
# @raycast.icon 🤖
# 检查是否有改动
if [ -z "$(git status --porcelain)" ]; then
echo "✅ No changes to commit"
exit 0
fi
# 添加改动
git add .
# 使用AI生成commit message
DIFF=$(git diff --cached)
COMMIT_MSG=$(echo "$DIFF" | claude-cli "Generate a conventional commit message for these changes. Only output the message, no explanation.")
echo "📝 Suggested commit message:"
echo "$COMMIT_MSG"
echo ""
# 提交
git commit -m "$COMMIT_MSG"
echo "✅ Committed successfully"
代码片段搜索
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Search Code Snippet
# @raycast.mode fullOutput
# @raycast.icon 🔎
# @raycast.argument1 { "type": "text", "placeholder": "Search term" }
SNIPPETS_DIR="$HOME/.config/snippets"
echo "🔍 Searching for: $1"
echo "─────────────────"
rg "$1" "$SNIPPETS_DIR" --color=always --heading
笔记管理类
快速笔记
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Quick Note
# @raycast.mode silent
# @raycast.icon 📝
# @raycast.argument1 { "type": "text", "placeholder": "Note content" }
NOTES_DIR="$HOME/Documents/Notes/Quick"
DATE=$(date +"%Y-%m-%d")
TIME=$(date +"%H:%M")
mkdir -p "$NOTES_DIR"
echo "[$TIME] $1" >> "$NOTES_DIR/$DATE.md"
echo "✅ Note saved"
今日笔记
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Open Today's Note
# @raycast.mode silent
# @raycast.icon 📅
NOTES_DIR="$HOME/Documents/Notes/Daily"
DATE=$(date +"%Y-%m-%d")
FILE="$NOTES_DIR/$DATE.md"
mkdir -p "$NOTES_DIR"
if [ ! -f "$FILE" ]; then
cat > "$FILE" << EOF
# Daily Note - $DATE
## 今日目标
- [ ]
## 工作日志
## 学习笔记
## 想法
## 明日计划
EOF
fi
open "$FILE"
会议笔记
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title New Meeting Note
# @raycast.mode silent
# @raycast.icon 🤝
# @raycast.argument1 { "type": "text", "placeholder": "Meeting title" }
NOTES_DIR="$HOME/Documents/Notes/Meetings"
DATE=$(date +"%Y-%m-%d")
FILE="$NOTES_DIR/$DATE-$1.md"
mkdir -p "$NOTES_DIR"
cat > "$FILE" << EOF
# $1
**日期**: $DATE
**参与者**:
## 讨论要点
## 决策事项
## 行动项
- [ ]
## 下一步
EOF
open "$FILE"
AI助手类
Ask AI
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Ask AI
# @raycast.mode fullOutput
# @raycast.icon 🤖
# @raycast.argument1 { "type": "text", "placeholder": "Your question" }
echo "🤖 Thinking..."
echo "─────────────────"
RESPONSE=$(claude-cli "$1")
echo "$RESPONSE"
解释命令
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Explain Command
# @raycast.mode fullOutput
# @raycast.icon 💡
# @raycast.argument1 { "type": "text", "placeholder": "Command to explain" }
echo "💡 Explaining: $1"
echo "─────────────────"
# 获取man文档
if man "$1" > /dev/null 2>&1; then
MAN=$(man "$1" | col -b | head -30)
EXPLANATION=$(echo "$MAN" | claude-cli "Explain this command in simple terms, with examples:")
else
EXPLANATION=$(claude-cli "Explain this command: $1")
fi
echo "$EXPLANATION"
翻译文本
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Translate
# @raycast.mode fullOutput
# @raycast.icon 🌐
# @raycast.argument1 { "type": "text", "placeholder": "Text to translate" }
# 自动检测语言并翻译
RESULT=$(claude-cli "Translate this to English if it's Chinese, or to Chinese if it's English: $1. Only output the translation.")
echo "$RESULT"
# 复制到剪贴板
echo "$RESULT" | pbcopy
echo ""
echo "✅ Copied to clipboard"
工具类
系统信息
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title System Info
# @raycast.mode fullOutput
# @raycast.icon 💻
echo "💻 System Information"
echo "───────────────────────"
echo "🖥️ Model: $(sysctl -n hw.model)"
echo "🧠 CPU: $(sysctl -n machdep.cpu.brand_string)"
echo "💾 RAM: $(sysctl -n hw.memsize | awk '{print $1/1024/1024/1024 " GB"}')"
echo "📦 macOS: $(sw_vers -productVersion)"
echo ""
echo "📊 Usage"
echo "───────────────────────"
echo "CPU: $(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}')"
echo "Memory: $(ps -A -o %mem | awk '{s+=$1} END {print s "%"}')"
echo "Disk: $(df -h / | awk 'NR==2 {print $5 " used"}')"
清理缓存
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Clean Caches
# @raycast.mode fullOutput
# @raycast.icon 🧹
echo "🧹 Cleaning caches..."
# Homebrew
if command -v brew &> /dev/null; then
echo "Cleaning Homebrew..."
brew cleanup
fi
# npm
if command -v npm &> /dev/null; then
echo "Cleaning npm..."
npm cache clean --force
fi
# Docker
if command -v docker &> /dev/null; then
echo "Cleaning Docker..."
docker system prune -f
fi
# macOS
echo "Cleaning system caches..."
rm -rf ~/Library/Caches/*
echo "✅ Cleanup complete!"
网络测速
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Network Speed Test
# @raycast.mode fullOutput
# @raycast.icon 📡
echo "📡 Testing network speed..."
echo ""
# 安装speedtest-cli: brew install speedtest-cli
if ! command -v speedtest-cli &> /dev/null; then
echo "❌ speedtest-cli not installed"
echo "Install: brew install speedtest-cli"
exit 1
fi
speedtest-cli --simple
生活类
番茄钟
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Pomodoro Timer
# @raycast.mode silent
# @raycast.icon 🍅
# @raycast.argument1 { "type": "text", "placeholder": "Task name", "optional": true }
DURATION=25 # 分钟
TASK=${1:-"Work"}
# 开启勿扰模式
osascript -e 'tell application "System Events" to keystroke "D" using {command down, shift down, option down, control down}'
# 显示通知
osascript -e "display notification \"Starting $TASK\" with title \"🍅 Pomodoro Started\""
# 后台计时
(
sleep $((DURATION * 60))
osascript -e "display notification \"Time to take a break!\" with title \"🍅 Pomodoro Complete\" sound name \"Glass\""
# 关闭勿扰模式
osascript -e 'tell application "System Events" to keystroke "D" using {command down, shift down, option down, control down}'
) &
echo "🍅 Pomodoro started: $TASK ($DURATION min)"
今日日程
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Today's Schedule
# @raycast.mode fullOutput
# @raycast.icon 📅
echo "📅 Today's Schedule"
echo "─────────────────────"
# 使用icalBuddy显示日程
# 安装: brew install ical-buddy
if command -v icalBuddy &> /dev/null; then
icalBuddy -n -iep "title,datetime" -ps "/: /" -po "datetime,title" eventsToday
else
echo "Install icalBuddy: brew install ical-buddy"
fi
健康提醒
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Health Reminder
# @raycast.mode silent
# @raycast.icon 💪
REMINDERS=(
"💧 喝水时间到了!"
"👀 休息眼睛,看看远方"
"🧘 站起来活动一下"
"🫁 做几个深呼吸"
)
# 随机选择一条提醒
RANDOM_REMINDER=${REMINDERS[$RANDOM % ${#REMINDERS[@]}]}
osascript -e "display notification \"$RANDOM_REMINDER\" with title \"健康提醒\""
安装脚本
自动安装Raycast脚本
#!/bin/bash
# install-raycast-scripts.sh
SCRIPT_DIR="$HOME/.config/raycast/scripts"
mkdir -p "$SCRIPT_DIR"
# 复制所有脚本
cp *.sh "$SCRIPT_DIR/"
# 添加执行权限
chmod +x "$SCRIPT_DIR"/*.sh
echo "✅ Raycast scripts installed to $SCRIPT_DIR"
echo "Open Raycast Settings → Extensions → Script Commands to see them"
使用技巧
1. 参数类型
text: 自由文本输入dropdown: 下拉选择optional: 可选参数
2. 模式选择
silent: 静默执行,只显示通知fullOutput: 显示完整输出compact: 紧凑输出
3. 调试脚本
# 在终端中测试
bash ~/path/to/script.sh "test argument"
# 查看错误
bash -x ~/path/to/script.sh
4. 常用技巧
# 复制结果到剪贴板
echo "result" | pbcopy
# 显示通知
osascript -e 'display notification "message" with title "title"'
# 打开文件/URL
open "file.txt"
open "https://example.com"
# 获取剪贴板内容
pbpaste