kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.36k stars 128 forks source link

apple script proof of concept #271

Closed christian-schulze closed 2 years ago

christian-schulze commented 3 years ago

Hi there, I'd like to share with you this proof-of-concept Apple Script integration, where you can call an Event in your javascript config via an Apple Script.

NOTE This PR is not in any shape to be merged, and I would like your guidance as to how best to implement this feature if you consider it worthwhile pursuing.

The following is an example javascript config:

const event = new Event('dispatch', function (event, data) {
  const text = data
    ? 'Event from AppleScript with data: ' + data
    : 'Event from AppleScript';

  Modal.build({ duration: 5, text }).show();
});

And the following is an example Apple Script:

tell application "Phoenix"
  dispatch
  dispatch event with "testing testing 1 2 3"
end tell

You could also run the following from the command line:

osascript -e 'tell application "Phoenix" to dispatch'

Properly implemented, this could address the following issues:

So what do you think, is this worth pursuing?

kasper commented 3 years ago

@christian-schulze Hey, cool idea! I’ll check this with thought once I have more time.

kasper commented 2 years ago

@christian-schulze This looks really cool and is actually a pretty simple solution to the problem! 👍 I wonder though, should we investigate instead using the Shortcuts app and command line tools since Apple is planning to deprecate AppleScript and Automator? (Also, I’m extremely sorry for the long delay for a response.)

christian-schulze commented 2 years ago

All good, I've since started hacking on all things linux, but still use a mac in my day job, so happy to come back to this. Can you provide a bit of detail about the Shortcuts app and other command line tools? I've not heard of this yet...

kasper commented 2 years ago

@christian-schulze Sure! Here’s some references: https://support.apple.com/en-gb/guide/shortcuts-mac/apdf22b0444c/mac and https://support.apple.com/en-gb/guide/shortcuts-mac/apd455c82f02/5.0/mac/12.0.