GithubHelp home page GithubHelp logo

japlscript / japlse Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.1 MB

Java API for AppleScript System Events

License: GNU Lesser General Public License v2.1

Java 100.00%
apple applescript system-events java japlscript macos

japlse's Introduction

LGPL 2.1 Maven Central Build and Test

JaplSE

JaplSE is a Java API for the AppleScript System Events based on JaplScript.

Installation

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

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

The Maven artifacts also contain sources and javadocs.

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

Usage

To use the generated code, do something like this:

import com.tagtraum.macos.systemevents.Application;

public class SendKeyStroke {

    public static void main(final String[] args) {
        final Application application = Application.getInstance();
        // send keystroke with no modifiers
        // to the frontmost app window
        application.keystroke("e", null);
    }
}

Or this:

import com.tagtraum.macos.systemevents.Application;

public class GetDownloadsFolder {

    public static void main(final String[] args) {
        final Application application = Application.getInstance();
        final String downloadsFolder = application.getDownloadsFolder().getPosixPath();
        System.out.println("Downloads folder: " + downloadsFolder);
    }
}

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.

japlse's People

Contributors

hendriks73 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.