Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / now-playing.js
Last active February 10, 2026 13:35
AppleScript and JXA scripts to get Now Playing info. Works on macOS 15.4+, including macOS 26 beta 1.
function run() {
const MediaRemote = $.NSBundle.bundleWithPath('/System/Library/PrivateFrameworks/MediaRemote.framework/');
MediaRemote.load
const MRNowPlayingRequest = $.NSClassFromString('MRNowPlayingRequest');
const appName = MRNowPlayingRequest.localNowPlayingPlayerPath.client.displayName;
const infoDict = MRNowPlayingRequest.localNowPlayingItem.nowPlayingInfo;
const title = infoDict.valueForKey('kMRMediaRemoteNowPlayingInfoTitle');
@SKaplanOfficial
SKaplanOfficial / SpeechRecognizer.scpt
Last active December 26, 2025 00:20
Sample JXA script for running speech recognition on audio. Shows how you can supply code blocks to ObjC methods in JXA (lines 33-37).
ObjC.import("AVFoundation");
ObjC.import('Speech');
ObjC.import("objc");
function recordForDuration(duration, destination) {
const settings = $.NSMutableDictionary.alloc.init;
settings.setValueForKey($.kAudioFormatAppleIMA4, $.AVFormatIDKey);
// Some macOS versions fail to link $.AVAudioFormat, so we manually get the class
const format = $.objc_getClass("AVAudioFormat").alloc.initWithSettings(settings);
@SKaplanOfficial
SKaplanOfficial / clean-finder-tags.scpt
Last active December 16, 2025 14:43
Script to automate hiding tags from Finder's sidebar by scripting Finder's Settings → Sidebar → Tags configuration UI and unchecking all except for a predefined allowlist. Reports which tags were hidden. Both files are functionally equivalent.
--
-- clean-finder-tags.scpt
--
-- Author: Stephen Kaplan
-- Date: 2025-12-16
--
-- Description:
-- Automates hiding tags from Finder's sidebar by scripting Finder's
-- Settings → Sidebar → Tags configuration UI and unchecking all tags
-- except for a predefined allowlist. Reports which tags were hidden.
@SKaplanOfficial
SKaplanOfficial / displaySettingsWindow.applescript
Created December 16, 2025 12:49
AppleScript handler to open an application's Settings window via its "Settings..." menu item.
on displaySettingsWindow(theApplication)
(*
* Opens the settings window for an application via its "Settings..." menu item.
* Returns a reference to the front window of the corresponding application process.
*)
set appName to missing value
if class of theApplication is text then
set appName to theApplication
else if class of theApplication is application then
@SKaplanOfficial
SKaplanOfficial / AppleScriptCheatsheet.md
Created April 5, 2023 23:47
Cheatsheet providing an overview of AppleScript's features.
title updated layout category prism_languages intro
AppleScript
2023-04-05
2017/sheet
macOS
applescript
AppleScript is a scripting language for automating macOS.

Running

@SKaplanOfficial
SKaplanOfficial / README.md
Created August 26, 2025 04:47
Overview of Bike's outline path behavior.

Outline paths can be significantly more performant than AppleScript's filtering operations.

For example, //*/run::@strong gets interpreted as:

  1. For all descendants of the root node,
  2. Look at their associated rich text by using run:: axes, then
  3. Run predicate against the attributes associated with each rich text run’s attributes.

Within Bike, outline paths can return different kinds of values:

@SKaplanOfficial
SKaplanOfficial / RaycastAIPrompts.md
Created April 4, 2023 20:04
My ad-hoc prompts for Raycast AI

Raycast AI Prompts

Content Generation

Title Prompt
Brainstorm Ideas Based On This Brainstorm 5 project ideas based on this text:
Create Action Items Generate a markdown list of action items to complete based on the following text, using a unique identifier for each item as bold headings. If there are any errors in the text, make actions items to fix them. In a sublist of each item, provide a description, priority, estimated level of difficulty, and a reasonable duration for the task. Here is the text:
Create Flashcards Create 3 Anki flashcards based on the following text. Format the response as markdown with the bold questions and plaintext answers. Separate each entry with ‘—‘. Here’s the text:
Generate Cheatsheet Generate a concise cheatsheet for the concepts in this text. Add additional details based on your own knowledge of the topic.
@SKaplanOfficial
SKaplanOfficial / NSTextStorageSubclass.swift
Created May 21, 2025 19:46 — forked from preble/NSTextStorageSubclass.swift
Base subclass of NSTextStorage in Swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
(() => {
ObjC.import("AppKit");
ObjC.import("WebKit");
ObjC.import("objc");
app = Application("iCab");
const baseURL = app.windows[0].currentTab.url();
// Size of WebView
const width = 1080;
@SKaplanOfficial
SKaplanOfficial / ScreenCapture.scpt
Created July 4, 2023 23:21
JXA script to take a screenshot and output a PNG file using ScreenCaptureKit. Provides an example of how to use the dispatch framework from JXA.
function run(argv) {
const outputPath = argv[2] // Path to output a .png to
const windowOnly = argv[3] // Whether to screenshot just the frontmost window (true/false)
ObjC.import('/System/Library/Frameworks/ScreenCaptureKit.framework');
ObjC.import('CoreMedia');
ObjC.import('CoreGraphics');
ObjC.import('CoreImage');
ObjC.import('dispatch');
ObjC.import('objc');