kofigumbs / multi

Create custom, lightweight macOS apps from websites
GNU General Public License v3.0
1.28k stars 39 forks source link

Possible to send javascript to Multi to execute? #137

Open NeighNeighNeigh opened 1 month ago

NeighNeighNeigh commented 1 month ago

Hello, I would like to use a script / url to have an instance of Mutli execute some javascript. If I open the console within Multi and enter something like javascript: alert("hello") I get great results… but I'm hoping here's a way to automate this in some fashion?

kofigumbs commented 1 month ago

Hello! I don’t think I understand what you’re trying to accomplish, sorry. Could you possibly share more specifics about your project and how you’d like it to work?

NeighNeighNeigh commented 1 month ago

Hi, yes of course ☺️

So I currently use Alfred to execute my own javascript within pages on Safari. Basically anything that might otherwise be a bookmarklet can actually be executed directly via keyboard shortcuts / system automation. I have ones for:

When you open the inspector on a Multi app, and choose Console, it is possible to enter javascript and have it execute on the current page. This is exactly the functionality I am looking for, I just need a way to programatically send the script to Multi rather than having to open the inspector console.

One way this could be implemented would be via a command line argument for example /Applications/Multi/My-Multi-App.app -js "insert script here"

Alternatively it could be handled via URL, Open Multi://path-to-my-multi-app?javascript=my-script-content

Or maybe by Applescript?

Anyway, I hope that clarifies the use case and helps inform your consideration for inclusion.

And finally, thank you so much for Multi! 🙏

kofigumbs commented 1 month ago

Gotcha, so there's no direct way to send JS to an already running Multi app, but you could script something up with Custom JS so that your app opens with custom behavior.

For instance, if you had a config like this, then the app will always look for the JS file in /Users/kofi/code/customize-internet-archive.js:

{
  "tabs": [
    {
      "title": "Internet Archive",
      "url": "https://archive.org",
      "customJs": [
        "file:///Users/kofi/code/customize-internet-archive.js"
      ]
    }
  ]
}

Then you could have a script that replaces the contents of that file and starts/restarts the Multi app:

MULTI_APP=Example.app

# write clipboard contents (as an example) to custom JS location
pbpaste > /Users/kofi/code/customize-internet-archive.js

# kill any running instances
ps aux | grep "[M]ulti/$MULTI_APP" | awk '{print $2}' | xargs kill

# start app
open -a "$MULTI_APP"

Does that you going in the right direction?