46 lines
1.8 KiB
Bash
Executable File
46 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# @raycast.schemaVersion 1
|
|
# @raycast.title Window Layout Manager
|
|
# @raycast.mode menu-bar
|
|
# @raycast.packageName Window Management
|
|
# @raycast.icon 💠
|
|
# @raycast.interval 1s
|
|
|
|
LAYOUT_FILE="$HOME/.hammerspoon/saved_layout.json"
|
|
STATE_FILE="/tmp/raycast_layout_state.json"
|
|
|
|
# Initialize state if missing
|
|
if [ ! -f "$STATE_FILE" ]; then
|
|
echo '{"countdown":300,"lastSaved":"Never"}' > "$STATE_FILE"
|
|
fi
|
|
|
|
# Load current state safely
|
|
COUNTDOWN=$(osascript -e 'tell application "System Events" to get value of property list item "countdown" of property list file "'"$STATE_FILE"'"' 2>/dev/null || echo "300")
|
|
LAST_SAVED=$(osascript -e 'tell application "System Events" to get value of property list item "lastSaved" of property list file "'"$STATE_FILE"'"' 2>/dev/null || echo "Never")
|
|
|
|
# Handle countdown decrement
|
|
COUNTDOWN=$((COUNTDOWN - 1))
|
|
if [ $COUNTDOWN -lt 0 ]; then
|
|
COUNTDOWN=300
|
|
/opt/homebrew/bin/node ~/Developer/raycast-scripts/layout_engine.js save silent > /dev/null 2>&1
|
|
LAST_SAVED=$(date +"%H:%M:%S")
|
|
fi
|
|
|
|
# Save the updated state
|
|
echo "{\"countdown\":$COUNTDOWN,\"lastSaved\":\"$LAST_SAVED\"}" > "$STATE_FILE"
|
|
|
|
# Calculate minutes and seconds
|
|
MINUTES=$((COUNTDOWN / 60))
|
|
SECONDS=$((COUNTDOWN % 60))
|
|
DISPLAY_TIME=$(printf "%d:%02d" $MINUTES $SECONDS)
|
|
|
|
# --- RAYCAST NATIVE MENU-BAR OUTPUT ---
|
|
# When mode is set to menu-bar, Raycast reads standard text output line-by-line
|
|
echo "$DISPLAY_TIME"
|
|
echo "---"
|
|
echo "📅 Last Saved: $LAST_SAVED"
|
|
echo "📸 Save Layout (⇧⌘W) | bash='/opt/homebrew/bin/node $HOME/Developer/raycast-scripts/layout_engine.js save' terminal=false"
|
|
echo "🔄 Restore Layout (⇧⌘R) | bash='/opt/homebrew/bin/node $HOME/Developer/raycast-scripts/layout_engine.js restore' terminal=false"
|
|
echo "🚀 Rescue Windows (⇧⌘⌃L) | bash='/opt/homebrew/bin/node $HOME/Developer/raycast-scripts/layout_engine.js rescue' terminal=false"
|