forked from adeelahmad/MacPilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacpilot_applescript.py
More file actions
84 lines (60 loc) · 2.52 KB
/
Copy pathmacpilot_applescript.py
File metadata and controls
84 lines (60 loc) · 2.52 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
#!/usr/bin/env python3
"""
MacPilot AppleScript Command Interface
Execute commands using the AppleScript-aware 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 execute_with_applescript_ai(command: str):
"""Execute command using AppleScript AI service"""
try:
# Import required modules
from main import AutomationFramework
sys.path.insert(0, str(Path(__file__).parent))
from applescript_ai_service import AppleScriptAIService
console.print(f"[cyan]🍎 MacPilot AppleScript executing:[/cyan] {command}")
console.print("-" * 60)
# Initialize framework
framework = AutomationFramework()
# Create and set AppleScript AI service
applescript_ai = AppleScriptAIService()
await framework.orchestrator.set_ai_service(applescript_ai)
console.print("[yellow]⚙️ Processing with AppleScript AI...[/yellow]")
# Execute the instruction
success = await framework.execute_instruction(command)
if success:
console.print("[green]✅ Command executed successfully![/green]")
else:
console.print("[yellow]⚠️ Command completed with warnings[/yellow]")
# Cleanup
framework.cleanup()
console.print("[dim]Framework cleaned up[/dim]")
return True
except Exception as e:
console.print(f"[red]❌ Command failed: {e}[/red]")
import traceback
traceback.print_exc()
return False
def main():
"""Main entry point"""
if len(sys.argv) < 2:
console.print("[red]Usage: python macpilot_applescript.py \"command\"[/red]")
console.print("\nExample commands:")
console.print(" python macpilot_applescript.py \"get current window\"")
console.print(" python macpilot_applescript.py \"take a screenshot\"")
console.print(" python macpilot_applescript.py \"show running applications\"")
console.print(" python macpilot_applescript.py \"what window is active\"")
sys.exit(1)
command = " ".join(sys.argv[1:])
# Run the command
success = asyncio.run(execute_with_applescript_ai(command))
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()