ScriptLib - Early and in progress scripting suite for Swift apps

Related tags

Animation ScriptLib
Overview

ScriptLib

Early and in progress scripting suite for Swift apps.

The goal is to create an API like AppleScript's standard suite, except implement using an embedded JavaScriptCore context. Manny macOS apps use this approach, but it looks like everyone is building their own solution. (Please let me know if there are open source solutions that I've missed). Here are some apps and related JavaScript API's to be inspired by:

To try out what's here:

  1. Open and run the Example app.

    Each app window has a text area that acts as a very simple script console. You can type the follow scripts into that window. On the other hand you'll have a much better experience if you setup Safari's script console to do this instead of using the in app script console. You setup Safari's script console like this:

    1. Open Safari

    2. Open the preferences and enable under "Advanced" the "Develop menu bar

    3. You should now see a new "Develop" menu item in Safari. Check the options "Automatically Show Web Inspector for JSContexts" and "Automatically Pause Connecting to JSContexts". With these options a new Safari window will open when you open the example app.

      You can also choose to open an existing context manually from Safari. When the example app is running there will be a context named "Scriptable ScriptContext" in Safari's "Develop" menu. Choose that to open the console.

    4. Now when you run the example app Safari should open a JavaScript console for the example apps script context. The following instructions should work about the same, but you'll have a nicer experience with autocomplete and better ways to inspect objects.

  2. Type app.version in the apps window (on Safari Console) and press Return. You should see 1.0.

  3. Enter app.beep(). It should beep!

  4. Enter app.documents[0].fileURL. You should see "undefined" if you haven't yet saved, or a URL object if you have saved.

  5. Enter app.documents[0].text. You should see "Hello World".

  6. Enter app.documents[0].text = "Hello, Hello World". You have assigned a new text value to the document.

That's about it! :)

But there are a number of basic design decision made.

  1. ScriptLib provides some behavior for free. For example the demo app didn't have to implement app.version, app.documents, app.windows, etc.

  2. ScriptLib makes it possible to extend this default scripting support. For example document.text is a custom property added by the demo app.

Generally scripting support is added by:

  1. Wrapping "Swift" objects inside a "JS" wrapper object. (Generally the "JS" object should weakly hold big reference types such as windows and documents so scripts don't create leaks).

  2. The scripting API is then exposed on that wrapper object by implementing protocol rooted at JSExport.

Todos

  • Implement features from AppleScript Standard Suite, combined with whatever useful standards can be understood by looking at existing app scripting APIs.

  • Add features for interacting with user. For example showAlert, getInput, chooseFromList, etc. These features consist of define JavaScript API and then native Swift implementation.

  • Add support for plugins. Generally plugins are just scripts that are automatically loaded and run.

    • Define plugin format
    • API to find plugins in common locations
    • API to load those plugins into a ScriptContext and call lifecycle events
    • API to allow plugins to subscribe to events such as documents and windows opening and closing.
    • API for plugins to contribute "commands". Maybe even standard UI that apps can use to browse and execute plugin contributed commands.
    • Note sure these ideas all make sense, but it would be pretty great to just include a lib and get all this for free.
  • Figure out some sane way to generate documentation. Ideally each JSExport protocol can be documented in Swift and then a script can extract that documentation and export in form suitable for JavaScript development.

Notes

  • There is mention in the code of iOS support. This would be nice eventually, but goal right now is just macOS.

  • This is all in exploratory phase. Maybe better way to do things. Let me know!

You might also like...
⛓ Easy to Read and Write Multi-chain Animations Lib in Objective-C and Swift.
⛓ Easy to Read and Write Multi-chain Animations Lib in Objective-C and Swift.

中文介绍 This project is inspired by JHChainableAnimations! Why Choose LSAnimator & CoreAnimator? You can write complex and easy-to-maintain animations in

Letters animation allows you to click on different letters and accordingly it will animate letters in a cool way. It has a very attractive UI and is very easy to use.
Letters animation allows you to click on different letters and accordingly it will animate letters in a cool way. It has a very attractive UI and is very easy to use.

Letters Animation Cool Letters Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

Numbers animation allows you to click on different numbers and accordingly it will animate numbers in a cool way. It has a very attractive UI and is very easy to use.
Numbers animation allows you to click on different numbers and accordingly it will animate numbers in a cool way. It has a very attractive UI and is very easy to use.

Numbers Animation Cool Numbers Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.
Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.

Reading Animation Cool Reading Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

An app that will help UI/UX designers and iOS developpers to easily work together, using demos and examples about iOS capabilities, limitations, ecosystem, ...

Demoapp Work in progress... 👀 What's about? It's an app built in SwiftUI that will help UI/UX designers and iOS developpers to work together smoothly

An elegant and flexible tweening library for iOS and tvOS.
An elegant and flexible tweening library for iOS and tvOS.

PMTween is an elegant and flexible tweening library for Objective-C, currently supporting the iOS and tvOS platforms. It offers sensible default funct

Widgets iOS 14 animation with 3D and dynamic shadow. Customisable transform and duration.
Widgets iOS 14 animation with 3D and dynamic shadow. Customisable transform and duration.

SPPerspective About Animatable widgets from iOS 14. Same animation for transform and shadow. Customisable duration, perspective and shadow also. For v

SwiftUI iOS application allowing users to create profiles and meet and chat with people
SwiftUI iOS application allowing users to create profiles and meet and chat with people

FindR SwiftUI iOS application allowing users to create profiles and meet and cha

Owner
Jesse Grosjean
Jesse Grosjean
Simple and powerful animated progress bar with dots

Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8.0+ Swift 3.0+ Installatio

Nikola Corlija 42 Dec 5, 2022
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
A simple animated progress bar in Swift

DSGradientProgressView Introduction DSGradientProgressView is a simple and customizable animated progress bar written in Swift. Inspired by GradientPr

Dhol Studio 445 Oct 13, 2022
Fully customizable circular progress bar written in Swift.

Fully customizable, circular progress bar written in Swift. Example To run the example project, clone the repo, and run pod install from the Example d

Lionheart Software 137 Nov 11, 2022
Circular progress Animation

JDCircularProgress JDCircularProgress is animateable UIView that can significantly enhance your users’ experiences and set your app apart from the res

Jawad Ali 8 May 16, 2022
RAProgressRing is the simplest approach to bringing circular progress in your application with minimal code.

RAProgressRing RAProgressRing is the simplest approach to bringing circular progress in your application with minimal code. Features It's customisable

Rohit Arora 5 Nov 4, 2022
Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

IBAnimatable 8.6k Jan 2, 2023
A travel companion for your apps, a solitaire friend for Walker

A travel companion for your apps, a solitaire friend for Walker. This library aims to make the job of using day to day animations easier, just with on

Ramon Gilabert 97 Apr 10, 2021
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
Easy to read and write chainable animations in Objective-C and Swift

Whats new in version 3.x? Swiftier syntax Swift 4 support Bug fixes and improvements Whats new in version 2.x? Re-architected from the ground up, no m

Jeff Hurray 3.2k Dec 30, 2022