Skip to content

Commit eca0ae6

Browse files
authored
Merge pull request #1 from ronnachum11/main
Add Windows Support
2 parents 8547d19 + 83645dc commit eca0ae6

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

operate/main.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import pyautogui
1212
import argparse
13+
import platform
1314

1415
from prompt_toolkit import prompt
1516
from prompt_toolkit.shortcuts import message_dialog
@@ -155,7 +156,13 @@ def main(model):
155156
style=style,
156157
).run()
157158

158-
os.system("clear") # Clears the terminal screen
159+
print("SYSTEM", platform.system())
160+
161+
if platform.system() == "Windows":
162+
os.system("cls")
163+
else:
164+
os.system("clear")
165+
159166

160167
print(f"{ANSI_GREEN}[Self-Operating Computer]\n{ANSI_RESET}{USER_QUESTION}")
161168
print(f"{ANSI_YELLOW}[User]{ANSI_RESET}")
@@ -215,7 +222,7 @@ def main(model):
215222

216223
function_response = ""
217224
if action_type == "SEARCH":
218-
function_response = mac_search(action_detail)
225+
function_response = search(action_detail)
219226
elif action_type == "TYPE":
220227
function_response = keyboard_type(action_detail)
221228
elif action_type == "CLICK":
@@ -303,7 +310,7 @@ def get_next_action_from_openai(messages, objective):
303310
# Call the function to capture the screen with the cursor
304311
capture_screen_with_cursor(screenshot_filename)
305312

306-
new_screenshot_filename = "screenshots/screenshot_with_grid.png"
313+
new_screenshot_filename = os.path.join("screenshots", "screenshot_with_grid.png")
307314

308315
add_grid_to_image(screenshot_filename, new_screenshot_filename, 500)
309316
# sleep for a second
@@ -477,9 +484,10 @@ def add_grid_to_image(original_image_path, new_image_path, grid_interval):
477484
# Filter for specific font name (e.g., 'Arial.ttf')
478485
font_path = next((path for path in font_paths if "Arial" in path), None)
479486
if not font_path:
480-
raise RuntimeError(
481-
"Specific TrueType font not found; install the font or check the font name."
482-
)
487+
if len(font_paths) > 0:
488+
font_path = font_paths[0]
489+
else:
490+
raise RuntimeError("No TrueType fonts found on the system.")
483491

484492
# Reduce the font size a bit
485493
font_size = int(grid_interval / 10) # Reduced font size
@@ -535,11 +543,15 @@ def keyboard_type(text):
535543
return "Type: " + text
536544

537545

538-
def mac_search(text):
539-
# Press and release Command and Space separately
540-
pyautogui.keyDown("command")
541-
pyautogui.press("space")
542-
pyautogui.keyUp("command")
546+
def search(text):
547+
if platform.system() == "Windows":
548+
pyautogui.press('win')
549+
else:
550+
# Press and release Command and Space separately
551+
pyautogui.keyDown("command")
552+
pyautogui.press("space")
553+
pyautogui.keyUp("command")
554+
543555
# Now type the text
544556
for char in text:
545557
pyautogui.write(char)
@@ -548,10 +560,13 @@ def mac_search(text):
548560
return "Open program: " + text
549561

550562

551-
def capture_screen_with_cursor(file_path="screenshots/screenshot_with_cursor.png"):
563+
def capture_screen_with_cursor(file_path=os.path.join("screenshots", "screenshot.png")):
552564
# Use the screencapture utility to capture the screen with the cursor
553-
subprocess.run(["screencapture", "-C", file_path])
554-
565+
if platform.system() == "Windows":
566+
screenshot = pyautogui.screenshot()
567+
screenshot.save(file_path)
568+
else:
569+
subprocess.run(["screencapture", "-C", file_path])
555570

556571
def extract_json_from_string(s):
557572
# print("extracting json from string", s)

requirements.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ Pillow==10.1.0
2626
prompt-toolkit==3.0.39
2727
PyAutoGUI==0.9.54
2828
pydantic==2.4.2
29-
pydantic-core==2.10.1
29+
pydantic_core==2.10.1
3030
PyGetWindow==0.0.9
3131
PyMsgBox==1.0.9
32-
pyobjc-core==10.0
33-
pyobjc-framework-Cocoa==10.0
34-
pyobjc-framework-Quartz==10.0
3532
pyparsing==3.1.1
3633
pyperclip==1.8.2
3734
PyRect==0.2.0
@@ -45,7 +42,7 @@ rubicon-objc==0.4.7
4542
six==1.16.0
4643
sniffio==1.3.0
4744
tqdm==4.66.1
48-
typing-extensions==4.8.0
45+
typing_extensions==4.8.0
4946
urllib3==2.0.7
5047
wcwidth==0.2.9
5148
zipp==3.17.0

0 commit comments

Comments
 (0)