Run AppleScripts from Plover
Project description
Plover Run AppleScript
This Plover extension plugin contains a command that can load in and run external AppleScript files.
The Problem
The reason this plugin exists is because of pain. The following is an example of how I used to run AppleScripts from my Plover dictionaries to perform some kind of automation task that could only be done on macOS using AppleScript:
"W-D": "{:COMMAND:SHELL:bash -ci 'osascript $STENO_DICTIONARIES/src/command/text/move-one-word-forward.scpt'}"
This solution does the following:
- uses the Plover Run Shell plugin to run a shell command from Python
- calls
bash
in interactive mode (-i
) so that the command can see environment variables ($STENO_DICTIONARIES
in this case) outside of the Plover environment - gets
bash
to use theosascript
command-line tool to load in and run the target compiled AppleScript (.scpt
file)
Running AppleScripts is generally slow, and constantly running one-off
commands that traverse a stack of Python->Shell->osascript
made them even
slower.
So, this plugin leverages PyXA to talk directly to Apple's APIs from Python, and keeps a local cache of loaded scripts to avoid needing to re-read in AppleScript files every time a command is run.
The above command now looks like this:
"W-D": "{:COMMAND:APPLESCRIPT:$STENO_DICTIONARIES/src/command/text/move-one-word-forward.scpt}"
The result is that commands at least feel like they run significantly faster, and I'm pretty sure it's because they actually are (but I don't have any hard benchmarks to objectively prove this).
Install
Until this plugin is added to the Plover registry, download from GitHub or clone using git:
git clone git@github.com:paulfioravanti/plover-run-applescript.git
cd plover-run-applescript
plover -s plover_plugins install .
Where
plover
in the command is a reference to your locally installed version of Plover. See the Invoke Plover from the command line page for details on how to create that reference.
- Restart Plover, open the Configuration screen (either click the Configuration
icon, or from the main Plover application menu, select
Preferences...
) - Open the Plugins tab
- Check the box next to
plover_run_applescript
to activate the plugin
[Future] Once this plugin is added to the Plover registry:
- In the Plover application, open the Plugins Manager (either click the Plugins
Manager icon, or from the
Tools
menu, selectPlugins Manager
). - From the list of plugins, find
plover-run-applescript
- Click "Install/Update"
- When it finishes installing, restart Plover
- After re-opening Plover, open the Configuration screen (either click the
Configuration icon, or from the main Plover application menu, select
Preferences...
) - Open the Plugins tab
- Check the box next to
plover_run_applescript
to activate the plugin
How To Use
Development
Clone from GitHub with git:
git clone git@github.com:paulfioravanti/plover-run-applescript.git
cd plover-run-applescript
Python Version
Plover's Python environment currently uses version 3.9 (see Plover's
workflow_context.yml
to confirm the current version).
So, in order to avoid unexpected issues, use your runtime version manager to make sure your local development environment also uses Python 3.9.x.
PyXA Version
This plugin depends on PyXA for all Python<->
AppleScript interoperations.
The dependency is currently pinned at version 0.0.9 due to later versions
of PyXA using Python 3.10 syntax (match case
etc) that is too new for
Plover's Python version.
Testing
Currently, all parts of this extension rely directly on Plover's environment, which makes testing difficult. So, as of now, no automated tests exist, and all testing has been done manually.
Linting
Attempts have been made to have at least some kind of code quality baseline with Pylint. Run the linter over the codebase with the following command:
pylint plover_run_applescript
Testing Changes
After making any code changes, install the plugin into Plover with the following command:
plover -s plover_plugins install .
Where
plover
in the command is a reference to your locally installed version of Plover. See the Invoke Plover from the command line page for details on how to create that reference.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file plover_run_applescript-0.1.0.tar.gz
.
File metadata
- Download URL: plover_run_applescript-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf601aac86db3099098a7e89b01d0291c8ec018d7fbcf7c9c7f06206b5b505b |
|
MD5 | 8c49a0ce5a2555e5a7b2a5f91dcac21a |
|
BLAKE2b-256 | 74f83bb0357502233e1a2b2730c0ed241dd68bb6692456656d8f5f2c1f5c8d13 |
File details
Details for the file plover_run_applescript-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: plover_run_applescript-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99f092abf31a9ba7c4d6c56f51023362570343288b3b02f0f93a78886b128d56 |
|
MD5 | 1b70f8fa2770045ea59270a9eb259872 |
|
BLAKE2b-256 | e901e3afbda83db2f069a11fa87966cb9d53eee51624dc091b98d5d8d17320c0 |