承接 joetannenbaum/php-mac-automator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joetannenbaum/php-mac-automator

最新稳定版本:0.1.0

Composer 安装命令:

composer require joetannenbaum/php-mac-automator

包简介

Automate your Mac with PHP

README 文档

README

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

composer require joetannenbaum/php-mac-automator

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

$automator->open('Warp');

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

// 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

  • 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

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

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('<?php')
    ->pause(.5)
    ->repeat(2, fn (Automator $remote) => $remote->enter()->pause(.25))
    ->type('echo "Hello World!";')
    ->run();

Code Snippet Demo

Roadmap

Right now you can basically automate anything you can do with your keyboard. I would like to add:

  • Mouse control
  • Window control
  • File system control
  • Browser control

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-24