octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.3k stars 949 forks source link

Does robotjs work on M1 apple silicon #631

Closed stevensanborn closed 2 years ago

stevensanborn commented 3 years ago

sorry im using "issues" to ask a basic question. I'm just wondering if anyone has tested if robotjs will work on the new apple M1 chip?

dukeliberal commented 3 years ago

@stevensanborn , are you test in m1 and does it work smoothly?

stevensanborn commented 3 years ago

I have not tested yet. I intend to eventually but if there is an issue im looking to know sooner rather than later

On Wed, Dec 30, 2020 at 8:27 PM dukehe notifications@github.com wrote:

@stevensanborn https://github.com/stevensanborn , are you test in m1 and does it work smoothly?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/octalmage/robotjs/issues/631#issuecomment-752861544, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHRE2GPYWQBZ2NT4G3NUELSXQKWFANCNFSM4USW5LRA .

-- Steven Sanborn Founder | Software Developer Feedtank (347) 687-2762

Ziao commented 3 years ago

Do you haven an m1 chip? I don't think many developers do yet, so if you do - please do test it and report back.

stevensanborn commented 3 years ago

I have the M1 and robotjs is working using rosetta

cliqer commented 3 years ago

I do get the following with an electron v11.2.1 app build with the latest electron-builder on an Intel Mac: image Are there any known workarounds of how to compile correctly? edit: Nevermind it works perfectly if compiled directly on an M1

danielehrhardt commented 3 years ago

Yes it does work. Use a terminal with Rosetta enabled.

pie6k commented 3 years ago

@danielehrhardt that's a good tip and it is indeed possible, but it actually means "robotjs does not work on m1"

raphaelmenges commented 2 years ago

I just integrated robotjs without any issue into my ARM64 Node.js project under macOS Big Sur on a Apple M1 chip. No Rosetta required :) Perhaps this issue is obsolete?

jroboyd commented 2 years ago

Not sure why this was closed I get the same error as @cliqer on an m1 macbook on macOS Big Sur. @raphaelmenges are you running arm64 node?

danielehrhardt commented 2 years ago

I just integrated robotjs without any issue into my ARM64 Node.js project under macOS Big Sur on a Apple M1 chip. No Rosetta required :) Perhaps this issue is obsolete?

How?

cliqer commented 2 years ago

@boydy12, it does work perfectly well.

danielehrhardt commented 2 years ago

@boydy12, it does work perfectly well.

  • use brew install nodejs@16. This will install the arm64 version of node (remove any other versions)
  • Make sure you have electron@15.3.4 (does not compile with v16 on windows if you use parallels)
  • use electron-builder@next
  • add "postinstall": "electron-builder install-app-deps" within your package.json
  • run yarn or npm -i

For me it worked to install v2 npm install @nut-tree/nut-js@2

cliqer commented 2 years ago

@danielehrhardt nutjs is a great alternative though around 10x slower on some of its functions/native implementations ie. pressing keys on the host system and out of scope within this thread.

jroboyd commented 2 years ago

Thanks guys, I think both nutjs and robotjs are maybe a bit overkill for my needs. I only need to run one set of key commands. I think just using exec could work for me better. I'm new to electron but being stuck to one version doesn't seem ideal to me. Definitely useful for other people looking to get this working.

This is my working code for macOS which is what i'm trying to achieve:

import { promisify } from "util";
const exec = promisify(require("child_process").exec);

const lock = async () => {
  await exec(`osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}`);
};

If there is a better way i'm open to suggestions.

cliqer commented 2 years ago

@boydy12 or simply use https://github.com/kujirahand/node-sendkeys-js or Applescript ;)

BTW, you are not stuck on a single version and following my suggestions you can compile robot js for any version of electron with arm64.

My recommendation was only if you need to also compile on windows 11 arm64 where it has some limitations with node-gyp and fails most of the time.