PHPackages                             joetannenbaum/php-mac-automator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. joetannenbaum/php-mac-automator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

joetannenbaum/php-mac-automator
===============================

Automate your Mac with PHP

0.1.0(3y ago)2116MITPHP

Since Apr 24Pushed 3y ago2 watchersCompare

[ Source](https://github.com/joetannenbaum/php-mac-automator)[ Packagist](https://packagist.org/packages/joetannenbaum/php-mac-automator)[ RSS](/packages/joetannenbaum-php-mac-automator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Mac Automator
=================

[](#php-mac-automator)

A simple wrapper around JXA scripts to allow you to control your Mac using PHP.

**👋 This is a work in progress.** I'm still finalizing the API and adding features, things may change.

That being said, it's pretty fun to play with. So please do so.

Installation
------------

[](#installation)

```
composer require joetannenbaum/php-mac-automator
```

Usage
-----

[](#usage)

```
use Automator\Automator;

$automator = new Automator();

// Open Warp terminal and list the files in the current directory
$automator->open('Warp')->typeAndEnter('ls')->run();

// or
Automator::make()->open('Warp')->typeAndEnter('ls')->run();
```

Opening Apps
------------

[](#opening-apps)

```
$automator->open('Warp');
```

Typing
------

[](#typing)

```
$automator->type('Hello World');
$automator->typeAndEnter('Hello World');

// With modifier keys (e.g. zoom in)
$automator->withCommand('+');
$automator->withShift('+');
$automator->withOption('+');
$automator->withControl('+');

// With multiple modifier keys (e.g. re-open last tab)
$automator->type('t', [Modifier::COMMAND, Modifier::SHIFT]);

// Helpers
$automator->enter();
$automator->tab();
$automator->backspace();
$automator->delete();
$automator->escape();
$automator->space();
$automator->arrowUp();
$automator->arrowDown();
$automator->arrowLeft();
$automator->arrowRight();
$automator->home();
$automator->end();
$automator->pageUp();
$automator->pageDown();

// Add modifer(s) to helper
$automator->enter(Modifier::SHIFT);
$automator->enter([Modifier::COMMAND, Modifier::SHIFT]);

// Set the typing speed
// 0.1 seconds between each character (default is 0.05)
$automator->setTypingSpeed(0.1);
```

Utilities
---------

[](#utilities)

```
// Open an app
$automator->open('Warp');

// Pause (seconds)
$automator->pause(1);

// Repeat a block of code (e.g. zoom in five times)
$automator->repeat(
    5,
    fn (Automator $remote) => $remote->typeWithCommand('+')->pause(.05),
);
```

Gotchas
-------

[](#gotchas)

- This script is actually sending keystrokes to your applications, but it's running at computer speed. Remember to insert reasonable `pause` statements in your scripts to allow your computer to catch up.
- If you are running a script, it will keep executing until the process itself is stopped or the script finishes. Meaning: If you tab away from the app the script is running in, if the script has more typing to do, it will continue typing. Keep that in mind.

Examples
--------

[](#examples)

### Demo a Raycast Extension

[](#demo-a-raycast-extension)

```
Automator::make()
    ->typeWithCommand(' ')
    ->pause(1)
    ->type('Warp Launch')
    ->pause(.5)
    ->enter()
    ->pause(.5)
    ->type('blog-joe-codes')
    ->pause(.5)
    ->enter()
    ->run();
```

[![Code Snippet Demo](images/raycast-demo.gif)](images/raycast-demo.gif)

### Demo a Code Snippet

[](#demo-a-code-snippet)

```
Automator::make()
    ->setTypingSpeed(.1)
    ->open('Visual Studio Code')
    ->pause(1)
    ->type('n', [Modifier::SHIFT, Modifier::COMMAND]) // Open a new window
    ->pause(.5)
    ->typeWithCommand('n') // Open a new file
    ->pause(.5)
    ->type('
