Skip to content

japlscript/japlsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LGPL 2.1 Maven Central Build and Test

JaplSA

JaplSA is a Java API for the AppleScript Standard Additions based on JaplScript.

Installation

JaplSA is released via Maven. You can install it via the following dependency:

<dependency>
    <groupId>com.tagtraum</groupId>
    <artifactId>japlsa</artifactId>
</dependency>

The Maven artifacts also contain sources and javadocs.

If you are using modules, its name is tagtraum.japlsa.

Usage

To use the generated code, do something like this:

import com.tagtraum.macos.standardadditions.ScriptingAddition;

public class DoubleBeep {

    public static void main(final String[] args) {
        final ScriptingAddition scriptingAddition = ScriptingAddition.getInstance();
        scriptingAddition.beep(2);
    }
}

Or this:

import com.tagtraum.macos.standardadditions.ScriptingAddition;
import java.awt.Color;

public class GetColor {

    public static void main(final String[] args) {
        final ScriptingAddition scriptingAddition = ScriptingAddition.getInstance();
        // show color picker dialog with RED as default color
        final Color color = scriptingAddition.chooseColor(Color.RED);
        System.out.println(color);
    }
}

API

You can find the complete API here.

AppleScript Sandbox

Since macOS 10.14 (Mojave), Apple imposed a sandbox on AppleScript. Therefore you may see dialog boxes requesting authorization to perform certain actions. After a while, these boxes simply disappear and there does not seem to be an easy way to authorize your app. In this case, you need to open the system preferences, navigate to Security & Privacy, Privacy, and then Automation, and make sure your app is allowed to remote control whatever app you are trying to remote control (see also this article).

If you are shipping a real app with a UI and not just a command line tool, you need to customize the sandbox permission dialog. You can do so by adding the key NSAppleEventsUsageDescription to your app bundle's /Contents/Info.plist file. For example:

[...]
<key>NSAppleEventsUsageDescription</key>
<string>SuperMusic uses AppleEvents to access your Music.app library,
        e.g., to set BPM values or create playlists.</string>
[...]

Apple's documentation for the keyword is here.