-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.sh
More file actions
130 lines (115 loc) · 3.48 KB
/
examples.sh
File metadata and controls
130 lines (115 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Practical examples of using MenuCLI
# These examples demonstrate real-world automation scenarios
MENU="./.build/release/menu"
echo "MenuCLI - Practical Examples"
echo "============================"
echo ""
# Example 1: Toggle Hidden Files in Finder
echo "Example 1: Toggle hidden files in Finder"
echo "-----------------------------------------"
cat << 'EOF'
# Toggle hidden files visibility
if $MENU check Finder "View > Show Hidden Files" --quiet; then
$MENU click Finder "View > Show Hidden Files"
else
# If the option doesn't exist, it might be "Hide Hidden Files"
$MENU click Finder "View > Hide Hidden Files"
fi
EOF
echo ""
# Example 2: Safari Automation
echo "Example 2: Clear Safari History"
echo "--------------------------------"
cat << 'EOF'
# Clear Safari history with confirmation check
if $MENU check Safari "History > Clear History..." --quiet; then
echo "Warning: This will clear Safari history"
read -p "Continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
$MENU click Safari "History > Clear History..."
fi
else
echo "Safari not running or menu not available"
fi
EOF
echo ""
# Example 3: VS Code Settings
echo "Example 3: Open VS Code Settings"
echo "---------------------------------"
cat << 'EOF'
# Open settings in Visual Studio Code
APP="Visual Studio Code"
if $MENU check "$APP" "Code > Preferences > Settings" --quiet; then
$MENU click "$APP" "Code > Preferences > Settings"
elif $MENU check "$APP" "Code > Settings..." --quiet; then
# Alternative menu structure
$MENU click "$APP" "Code > Settings..."
else
echo "VS Code not running"
fi
EOF
echo ""
# Example 4: Batch Operations
echo "Example 4: Batch Window Operations"
echo "-----------------------------------"
cat << 'EOF'
# Open multiple new windows in different apps
APPS=("Safari" "Finder" "Terminal")
for app in "${APPS[@]}"; do
if $MENU check "$app" "File > New Window" --quiet; then
$MENU click "$app" "File > New Window"
echo "✓ Opened new window in $app"
else
echo "✗ Could not open window in $app"
fi
done
EOF
echo ""
# Example 5: Conditional Workflow
echo "Example 5: Smart Screenshot Workflow"
echo "-------------------------------------"
cat << 'EOF'
# Take screenshot and open in Preview
function smart_screenshot() {
# Take screenshot (using macOS built-in)
screencapture -i ~/Desktop/screenshot.png
# Open in Preview if it exists
if [ -f ~/Desktop/screenshot.png ]; then
open -a Preview ~/Desktop/screenshot.png
sleep 1
# Annotate using Preview menu
if $MENU check Preview "Tools > Annotate > Rectangle" --quiet; then
$MENU click Preview "Tools > Annotate > Rectangle"
echo "Ready to annotate!"
fi
fi
}
EOF
echo ""
# Example 6: Application State Check
echo "Example 6: Check Application State"
echo "-----------------------------------"
cat << 'EOF'
# Check if an app has unsaved changes
function check_unsaved() {
local app=$1
# In many apps, "File > Save" is disabled if no changes
if $MENU check "$app" "File > Save" --quiet; then
echo "⚠️ $app has unsaved changes"
return 0
else
echo "✓ $app has no unsaved changes"
return 1
fi
}
# Usage:
check_unsaved "TextEdit"
EOF
echo ""
echo "============================"
echo "End of Examples"
echo ""
echo "These examples show how MenuCLI can be integrated into"
echo "shell scripts for powerful macOS automation workflows."