Skip to content

krupagaliya/FunctionMac

Repository files navigation

FunctionMac 🍎

Python 3.12+ macOS Ollama FunctionGemma License: MIT

Natural language control for macOS powered by FunctionGemma and Ollama. Control system settings, automate tasks, and manage apps using plain English. Runs 100% locally—no cloud or Internet required to run this.

✨ Features

  • 🗣️ Natural Language Interface - Control your Mac using plain English
  • 🔒 100% Local - No data leaves your machine, powered by Ollama
  • 🤖 FunctionGemma Integration - Google's efficient function-calling model
  • 🖥️ 45 macOS Functions - System control, GUI automation, app integration
  • 🌐 Web Interface - Beautiful Streamlit UI for easy access
  • Fast & Lightweight - Runs on Apple Silicon and Intel Macs

🎬 Demo

FunctionMac Demo

Test Interface

Streamlit Web Interface

CLI Assistant

CLI Assistant Demo

🎯 What Can It Do?

System Control

  • Volume and brightness adjustment
  • Dark/Light mode switching
  • Do Not Disturb toggle
  • Screenshot capture

GUI Automation

  • Mouse clicks, drags, and position tracking
  • Keyboard typing and shortcuts
  • Screen scrolling

App Integration

  • Open/close applications
  • Create reminders
  • Control Music playback
  • Access calendar events
  • Send iMessages

Data Processing

  • Mathematical calculations
  • Statistical analysis
  • QR code generation
  • Wi-Fi network scanning
  • Text file analysis

🏗️ Architecture

User Input (Natural Language)
    ↓
FunctionGemma via Ollama
    ↓
Function Mapping & Parameter Extraction
    ↓
macOS Function Execution (AppleScript + Python APIs)
    ↓
Result Processing & Response Generation

📋 Requirements

  • macOS 11.0+ (Big Sur or later)
  • Python 3.12+
  • Ollama installed and running
  • FunctionGemma model

🚀 Installation

1. Install Ollama

Download ollama application from here: https://ollama.com/

# Pull FunctionGemma model
ollama run functiongemma:270m

2. Clone the Repository

git clone https://github.com/krupagaliya/FunctionMac.git
cd FunctionMac

3. Install Python Dependencies

# Create virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

4. Grant Permissions (Optional, it will ask whenever its needed)

Some features require macOS permissions:

  1. System Settings → Privacy & Security → Accessibility

    • Add Terminal or your Python IDE
  2. System Settings → Privacy & Security → Automation

    • Allow control of System Events
  3. System Settings → Privacy & Security → Screen Recording

    • Required for screenshots

5. Verify Installation

python test_system.py

📖 Usage

Option 1: Web Interface (Recommended)

Launch the Streamlit web app:

streamlit run streamlit_app.py

It will show the Localhost URL and something like http://localhost:8504 open it in your browser to access:

  • Function browser by category
  • Direct function execution
  • Quick action buttons
  • Real-time results display

Option 2: Interactive CLI

Start the AI assistant in your terminal:

python macos_ai_assistant.py

Example conversation:

🗣️  You: Take a screenshot and save it to desktop
🤖 Assistant: I've taken a screenshot and saved it to your desktop

🗣️  You: Set volume to 50 percent
🤖 Assistant: Volume has been set to 50%

🗣️  You: Turn on dark mode
🤖 Assistant: Appearance has been set to Dark mode

🗣️  You: What's my battery level?
🤖 Assistant: Your battery is at 85% and currently charging

Option 3: Programmatic Usage

from macos_ai_assistant import MacOSAIAssistant

# Initialize the assistant
assistant = MacOSAIAssistant()

# Process a query
result = assistant.process_query("Set brightness to 50%")

if result['success']:
    print(f"Response: {result['final_response']}")
    print(f"Functions called: {[fc['function'] for fc in result['function_calls']]}")
else:
    print(f"Error: {result['error']}")

💬 Example Commands

System Control

"Set volume to 50 percent"
"Mute the volume"
"Turn on dark mode"
"Set brightness to 80%"
"Enable Do Not Disturb"

Information

"Show me battery information"
"What's my CPU usage?"
"Get my screen resolution"
"Where is my mouse cursor?"
"What time is it?"

File Operations

"Take a screenshot"
"Find all PDF files in Downloads"
"Copy this to clipboard: Hello World"
"What's in my clipboard?"

Applications

"Open Safari"
"Open Calculator"
"List running applications"
"Quit Finder"

GUI Automation

"Click at coordinates 500, 300"
"Type 'Hello World'"
"Send keyboard shortcut cmd+c"
"Scroll down 5 clicks"

App Integration

"Create a reminder: Buy groceries"
"Show my calendar events"
"Play music"
"Pause the music"

Data Processing

"Calculate sqrt(16) + sin(pi/2) * 10"
"Analyze these numbers: 10, 20, 30, 40, 50"
"Generate a QR code for https://github.com"
"Scan for Wi-Fi networks"

📁 Project Structure

FunctionMac/
├── macos_ai_assistant.py       # Main AI assistant orchestrator
├── macos_functions.py          # Core macOS function implementations (40+ functions)
├── streamlit_app.py            # Web interface
├── test_system.py              # System verification tests
├── comprehensive_function_test.py  # Full function test suite
├── requirements.txt            # Python dependencies
├── README.md                   # Documentation
├── LICENSE                     # MIT License

🔧 Technical Details

FunctionGemma Integration

  • Model: functiongemma:270m (lightweight, fast)
  • Function Definitions: Automatically exposed as tools
  • Parameter Extraction: NL → structured function calls

macOS Integration Methods

Method Use Case
AppleScript System Events, app control
subprocess Shell commands, system tools
PyAutoGUI Mouse/keyboard automation
psutil System information
ctypes Low-level macOS APIs

Supported Functions (45)

Click to expand full function list

System Information

  • get_battery_info, get_system_info, get_cpu_usage
  • get_memory_usage, get_disk_usage, get_screen_info
  • get_current_datetime

Audio Control

  • get_volume, set_volume, mute_volume, unmute_volume

Display Control

  • get_brightness, set_brightness
  • get_current_theme, change_theme

Focus Mode

  • enable_do_not_disturb, disable_do_not_disturb

Clipboard

  • copy_to_clipboard, get_clipboard_content, paste_from_clipboard

File Operations

  • take_screenshot, find_files, open_file, open_folder
  • process_text_file

Applications

  • open_application, quit_application, list_running_applications

GUI Automation

  • click_at_coordinates, drag_mouse, get_mouse_position
  • type_text, send_keyboard_shortcut, scroll_screen

App Integration

  • create_reminder, get_calendar_events
  • control_music, send_message

Data Processing

  • calculate_expression, analyze_data
  • generate_qr_code, get_wifi_networks

🐛 Troubleshooting

Ollama Issues

Make sure Ollama is running

# Ollama has functiongemma:270m model 
ollama ls

# Test the model
ollama run functiongemma:270m "Hello"

Permission Errors

If functions fail with permission errors:

  1. Open System SettingsPrivacy & Security
  2. Grant permissions to Terminal/IDE for:
    • Accessibility
    • Automation
    • Screen Recording (for screenshots)
    • Full Disk Access (for file operations)

🔮 Roadmap & Next Steps

I am working on expanding FunctionMac with advanced capabilities and fine-tuning the AI model.

🧠 Model Improvement Fine-tuning FunctionGemma: Specifically training the model on macOS-specific function calls to improve accuracy and parameter extraction for complex queries.

🚧 Upcoming Feature Categories

  1. Window & Space Management (Split view, stage manager)
  2. Network & Connectivity (Wi-Fi, Bluetooth toggle)
  3. Quick Actions & Shortcuts (Time savers)
  4. Smart Clipboard & Text Processing (History, formatting)
  5. Timer & Productivity (Pomodoro, alarms)
  6. Audio & Media Control (Enhanced playback)
  7. File Operations (Compression, advanced search)
  8. System Maintenance (Cache cleaning, updates)
  9. Accessibility & Display (Zoom, contrast)
  10. Smart Automation (Multi-step workflows)

🤝 Contributing

Contributions are welcome! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

⚠️ Known Limitations

  • Model Accuracy: FunctionGemma (270m) may occasionally misinterpret complex or ambiguous natural language commands
  • Best Practice: Use specific, clear commands (e.g., "set volume to 50%" instead of "make it louder")
  • Multi-step Commands: Break complex requests into individual commands for better results

💡 I am actively working on fine-tuning FunctionGemma to improve accuracy. See Roadmap. Contributions are welcome!

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📬 Support


Made with ❤️ for the macOS community, powered by Google's FunctionGemma model

About

Natural language control for macOS powered by FunctionGemma and Ollama. Control system settings, automate tasks, and manage apps using plain English. functions including volume/brightness control, screenshots, file operations, GUI automation, and app integration. Runs 100% locally—no cloud required.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages