joetannenbaum/php-mac-automator
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
pausestatements 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();
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();
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
joetannenbaum/php-mac-automator 适用场景与选型建议
joetannenbaum/php-mac-automator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 23, 最近一次更新时间为 2023 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 joetannenbaum/php-mac-automator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joetannenbaum/php-mac-automator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-24

