1010import subprocess
1111import pyautogui
1212import argparse
13+ import platform
1314
1415from prompt_toolkit import prompt
1516from 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
556571def extract_json_from_string (s ):
557572 # print("extracting json from string", s)
0 commit comments