Repository navigation
Run AppleScript in-process on macOS instead of spawning osascript - #19
Merged
LabyStudio merged 1 commit intoOct 3, 2026
Merged
Conversation
Every request (at least three per tick, six on a track change) spawned an osascript process. macOS registers each of them with Launch Services as an application of its own, attributed to the application that started the JVM. Inside a game started by a launcher, every poll put another launcher icon into the Dock, several per second. The script now runs through the Open Scripting Architecture inside the JVM: compiled once, executed per request, no child processes and about 8 ms per request instead of about 130 ms. AppleScript's default send and active procedures pump the calling thread's event loop, which hangs off the main thread while the main thread runs its own loop, so replies are awaited with AESendMessage instead. osascript remains the fallback if the native path is unavailable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS every
AppleScript.executespawned anosascriptprocess: at least three per tick (track id, player state, position), six when the track changes.macOS registers each of those processes with Launch Services as a foreground application, attributed to the application that started the JVM. When the JVM is a game started by a launcher (LabyMod with the Spotify addon on Minecraft 26.3), every poll adds another launcher icon to the Dock. That's several icons per second for as long as the game runs. The system log shows it for every
osascriptchild:Fix
AppleScriptEngineruns the script inside the JVM through the Open Scripting Architecture (Carbon, via JNA):kOSAModeDisplayForHumans, which matchesosascript's output exactly (strings unquoted, reals, lists).javalauncher.AESendMessagewaits on a reply port instead.executeis synchronized, since the tick thread and media keys can call it concurrently.If the native path can't be initialised,
AppleScriptfalls back toosascriptas before.Testing (macOS 27, Apple Silicon, Spotify running)
osascript's output exactly.SpotifyAppleScriptgetters work. Runtime and compile errors are reported.SpotifyAPIFactory.create()+initialize()ran for 6 s:onConnect,onTrackChangedandonPlayBackChangedfired, and 0 child processes were started (previously at least 3 per second).osascriptspawn.osascriptchildren and no additional Dock icons.🤖 Generated with Claude Code