-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_textedit.sh
More file actions
executable file
·126 lines (103 loc) · 2.87 KB
/
test_textedit.sh
File metadata and controls
executable file
·126 lines (103 loc) · 2.87 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
#!/bin/bash
# Test script for Geisterhand - Opens TextEdit, writes text, maximizes, and saves
# Requires GeisterhandApp to be running on port 7676
API="http://127.0.0.1:7676"
FILENAME="geisterhand_test_$(date +%Y%m%d_%H%M%S).txt"
# Helper function for API calls
key_press() {
local key="$1"
local modifiers="$2"
if [ -z "$modifiers" ]; then
curl -s -X POST "$API/key" -H "Content-Type: application/json" -d "{\"key\": \"$key\"}"
else
curl -s -X POST "$API/key" -H "Content-Type: application/json" -d "{\"key\": \"$key\", \"modifiers\": $modifiers}"
fi
echo ""
}
type_text() {
local text="$1"
# Use jq to properly escape text for JSON
local json_payload=$(jq -n --arg text "$text" '{text: $text}')
curl -s -X POST "$API/type" -H "Content-Type: application/json" -d "$json_payload"
echo ""
}
click_at() {
local x="$1"
local y="$2"
curl -s -X POST "$API/click" -H "Content-Type: application/json" -d "{\"x\": $x, \"y\": $y}"
echo ""
}
# Check if jq is available
if ! command -v jq &> /dev/null; then
echo "ERROR: jq is required. Install with: brew install jq"
exit 1
fi
# Check if server is running
echo "Checking Geisterhand server status..."
STATUS=$(curl -s "$API/status")
if [ $? -ne 0 ]; then
echo "ERROR: Cannot connect to Geisterhand server. Is GeisterhandApp running?"
exit 1
fi
echo "Server is running!"
echo ""
# Step 1: Open Spotlight
echo "Opening Spotlight..."
key_press "space" '["cmd"]'
sleep 0.8
# Step 2: Type "TextEdit" and press Enter
echo "Launching TextEdit..."
type_text "TextEdit"
sleep 0.5
key_press "return"
sleep 2
# Step 3: Create new document
echo "Creating new document..."
key_press "n" '["cmd"]'
sleep 1
# Step 4: Type text
echo "Typing text..."
type_text "Hello from Geisterhand!
This is a test of the macOS automation tool.
Special characters work now: _-/~:()[]{}
It works!"
sleep 0.5
# Step 5: Maximize window (fullscreen toggle)
echo "Toggling fullscreen..."
key_press "f" '["cmd", "ctrl"]'
sleep 1.5
# Exit fullscreen
echo "Exiting fullscreen..."
key_press "f" '["cmd", "ctrl"]'
sleep 1
# Step 6: Save the file
echo "Opening save dialog..."
key_press "s" '["cmd"]'
sleep 1
# Go to folder dialog (Cmd+Shift+G)
echo "Opening Go to Folder..."
key_press "g" '["cmd", "shift"]'
sleep 0.8
# Type the Downloads path
echo "Typing path..."
type_text "~/Downloads"
sleep 0.3
# Press Enter to navigate to Downloads
echo "Navigating to Downloads..."
key_press "return"
sleep 1
# Now focus is back on Save As field - type the filename
echo "Typing filename in Save As field..."
# The Save As field should be focused, just type the filename
type_text "$FILENAME"
sleep 0.5
# Click the Save button (or press Enter)
echo "Saving..."
key_press "return"
sleep 1
# Close TextEdit
echo "Closing TextEdit..."
key_press "q" '["cmd"]'
sleep 0.5
echo ""
echo "Done! File should be saved as: ~/Downloads/$FILENAME"