WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

How do I configure my application to receive an AppleEvent?

Forums > macOS

I'm working on an application to queue up work (URLs to fetch) and then batch do the work upon request. I'd like to be able to send an AppleEvent (via an AppleScript) with a URL to my app, semantically saying, "Add this URL to your list of stuff to do."

So, what do I have to do withing my SwiftUI application to make it able to receive such a message?

   

The only tutorial I'm aware of that uses Swift instead of ObjC is the following from 2016. Also, it looks llike you have to use NSApplication, not the new App struct, but that doesn’t preclude SwiftUI.

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

It might be easier to use an x-callback-url instead of AppleScript:

https://github.com/ValentinWalter/Middleman

I've thought about this myself, which is why I have bookmarks to these resources, but I haven’t actually tried it. I hope you post any tips you develop.

1      

Thanks for these references! I'm in the middle of moving, but this will likely be my next project in a couple of weeks. I'll definitely write an update!

   

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.