()
| 73 | |
| 74 | |
| 75 | async def main(): |
| 76 | try: |
| 77 | workspace = Cocoa.NSWorkspace.sharedWorkspace() |
| 78 | state = FolderCreationState() |
| 79 | |
| 80 | print(f'\nLaunching {NOTES_APP_NAME} app...') |
| 81 | success = workspace.launchApplication_(NOTES_APP_NAME) |
| 82 | |
| 83 | if not success: |
| 84 | print(f'❌ Failed to launch {NOTES_APP_NAME} app') |
| 85 | return |
| 86 | |
| 87 | # Find Notes app |
| 88 | await asyncio.sleep(2) |
| 89 | notes_app = None |
| 90 | for app in workspace.runningApplications(): |
| 91 | if app.bundleIdentifier() and NOTES_BUNDLE_ID.lower() in app.bundleIdentifier().lower(): |
| 92 | notes_app = app |
| 93 | print(f'\nFound {NOTES_APP_NAME} app!') |
| 94 | print(f'Bundle ID: {app.bundleIdentifier()}') |
| 95 | print(f'PID: {app.processIdentifier()}') |
| 96 | break |
| 97 | |
| 98 | if not notes_app: |
| 99 | print(f'❌ Could not find {NOTES_APP_NAME} app') |
| 100 | return |
| 101 | |
| 102 | is_ready = await wait_for_app_ready(notes_app) |
| 103 | if not is_ready: |
| 104 | print(f'❌ App failed to become ready') |
| 105 | return |
| 106 | |
| 107 | builder = MacUITreeBuilder() |
| 108 | max_steps = 10 # Limit the number of interaction steps |
| 109 | goal_achieved = False |
| 110 | for step in range(max_steps): |
| 111 | if goal_achieved: |
| 112 | print('✅ Goal already achieved, stopping further actions') |
| 113 | break |
| 114 | |
| 115 | print(f'\n--- Step {step + 1}/{max_steps} ---') |
| 116 | root = await builder.build_tree(notes_app.processIdentifier(), notification_callback=notification_handler) |
| 117 | |
| 118 | if not root: |
| 119 | print(f'❌ Failed to build UI tree for {NOTES_APP_NAME}') |
| 120 | break |
| 121 | |
| 122 | ui_tree_string = root.get_clickable_elements_string() |
| 123 | |
| 124 | # Add state context to the prompt |
| 125 | state_context = state.get_context(ui_tree_string) |
| 126 | |
| 127 | prompt = f"""You are an intelligent agent designed to automate tasks within the macOS "Notes" application. |
| 128 | |
| 129 | Current Goal: Create a new folder in the notes app called 'Ofir folder'. |
| 130 | Current Step: {state_context} |
| 131 | |
| 132 | To create a new folder, you need to: |
no test coverage detected