forked from adeelahmad/MacPilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_direct_applescript.py
More file actions
136 lines (102 loc) · 4.74 KB
/
Copy pathtest_direct_applescript.py
File metadata and controls
136 lines (102 loc) · 4.74 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
131
132
133
134
135
136
#!/usr/bin/env python3
"""
Direct AppleScript Test - Bypass AI entirely
Test the new AppleScript capabilities directly without going through the AI service.
"""
import sys
import asyncio
from pathlib import Path
# Add automation framework to path
sys.path.insert(0, str(Path(__file__).parent / "automation_framework"))
from rich.console import Console
from rich.panel import Panel
from rich.json import JSON
console = Console()
async def test_applescript_directly():
"""Test AppleScript capabilities directly"""
console.print("[bold cyan]🍎 Direct AppleScript Test[/bold cyan]")
console.print("=" * 50)
try:
# Import the generic actor directly
from actors.generic.mouse_keyboard import GenericActorStack
console.print("1. 🚀 Initializing Generic Actor...")
actor = GenericActorStack()
console.print("2. 📋 Testing capabilities...")
capabilities = actor.get_capabilities()
applescript_actions = {k: v for k, v in capabilities.items()
if 'script' in k.lower() or k in ['get_current_window', 'screenshot']}
console.print("Available AppleScript actions:")
for action, details in applescript_actions.items():
console.print(f" • [green]{action}[/green]: {details['description']}")
console.print("\n3. 🪟 Getting current window info...")
try:
window_info = await actor.execute_action('get_current_window')
console.print(Panel(
JSON.from_data(window_info),
title="Current Window Info"
))
except Exception as e:
console.print(f"[red]❌ get_current_window failed: {e}[/red]")
console.print("\n4. 📸 Testing screenshot...")
try:
screenshot_result = await actor.execute_action('screenshot', filename='test_screenshot.png')
if screenshot_result:
console.print("[green]✅ Screenshot taken successfully![/green]")
else:
console.print("[yellow]⚠️ Screenshot may have failed[/yellow]")
except Exception as e:
console.print(f"[red]❌ Screenshot failed: {e}[/red]")
console.print("\n5. 🍎 Testing custom AppleScript...")
custom_script = '''
tell application "System Events"
try
set appList to name of every application process whose visible is true
set appCount to count of appList
return "Running apps: " & appCount & " - " & (item 1 of appList) & ", " & (item 2 of appList)
on error
return "Error getting app list"
end try
end tell
'''
try:
script_result = await actor.execute_action('run_applescript', script=custom_script)
console.print(f"[cyan]AppleScript result:[/cyan] {script_result}")
except Exception as e:
console.print(f"[red]❌ Custom AppleScript failed: {e}[/red]")
console.print("\n6. 🧹 Cleaning up...")
await actor.cleanup()
console.print("\n[green]✅ Direct AppleScript test complete![/green]")
except Exception as e:
console.print(f"[red]❌ Test failed: {e}[/red]")
import traceback
traceback.print_exc()
async def test_simple_applescript():
"""Test even simpler AppleScript execution"""
console.print("\n[bold yellow]🔧 Simple AppleScript Test[/bold yellow]")
console.print("=" * 30)
try:
# Test direct osascript execution
console.print("Testing direct osascript...")
process = await asyncio.create_subprocess_exec(
'osascript', '-e', 'tell application "System Events" to get name of first application process whose frontmost is true',
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if stderr:
console.print(f"[red]Error: {stderr.decode()}[/red]")
else:
console.print(f"[green]Front app: {stdout.decode().strip()}[/green]")
except Exception as e:
console.print(f"[red]❌ Simple test failed: {e}[/red]")
async def main():
"""Run all tests"""
# Test direct actor capabilities
await test_applescript_directly()
# Test simple AppleScript
await test_simple_applescript()
console.print("\n🎯 Summary")
console.print("This test bypassed the AI entirely and called AppleScript actions directly.")
console.print("If this works, we know the AppleScript integration is functional.")
if __name__ == "__main__":
asyncio.run(main())