Witterquick
Witterquick

Reputation: 6150

making macOS app scriptable at a 'Linux' way

I've implemented a macOS app. Is it possible to make it scriptable? for example - let's say the app's name is "myApp", and within the app you can add/delete new users, and press a button, I want to be able to control the app from the terminal with something like this:

//initiate commands:

myApp --addUser 'Bob'

//when the app is already running commands:

myApp --pressButton 'BigRedButton'

Or in other words, something like: myApp ...

P.S - I know about AppleScript, but never tried it before, and it seems a little too complicated for the things I want to do, so I'm wondering if there's another way, or maybe AppleScript is the only way..

Upvotes: 0

Views: 153

Answers (1)

MMac
MMac

Reputation: 483

raywenderlich.com has two excellent tutorials on the kind of scripting you're asking about.

I would agree that there's a lot you can do with Applescript, and it's pretty straightforward to do if you're already comfortable working in the language. Here's a tutorial on how to implement Applescriptability into your app:

https://www.raywenderlich.com/1033-making-a-mac-app-scriptable-tutorial

But to your point, yes, this is only step 1 if you're dealing with Applescript. Step 2 is writing an actual Applescript to pass the commands you're looking to execute to your application.

And no, that still doesn't get you what you're asking for. If what you really need to do is pass commands from the command line, I'd start here:

https://www.raywenderlich.com/511-command-line-programs-on-macos-tutorial

That tutorial deals more with how to create an actual command-line app (that is, one with no actual GUI), but the principles are going to be the same & you should be able to use these same methods to implement code into your app that will allow it to listen for commands issued from the command line.

Upvotes: 1

Related Questions