Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / ExtractTextFromVideo.scpt
Created May 14, 2023 08:00
JXA script to extract text from a video file by analyzing individual frames with the Vision framework.
(() => {
ObjC.import("objc");
ObjC.import("CoreMedia");
ObjC.import("Foundation");
ObjC.import("AVFoundation");
ObjC.import("Vision");
ObjC.import("AppKit");
// Load the video file
const assetURL = $.NSURL.fileURLWithPath(
@SKaplanOfficial
SKaplanOfficial / reverseGeocodeCurrrentLocation.js
Created April 25, 2023 21:49
JXA script to reverse geocode the user's current location
(() => {
ObjC.import('CoreLocation')
app = Application.currentApplication()
app.includeStandardAdditions = true
if (!$['CLLocationManagerDelegate']) {
ObjC.registerSubclass({
name: 'CLLocationManagerDelegate',
superclass: 'NSObject',
protocols: ['CLLocationManagerDelegate'],
@SKaplanOfficial
SKaplanOfficial / SpeechRecognitionFromFile.js
Created April 25, 2023 20:42
JXA script to extract spoken word content from an audio file
(() => {
ObjC.import('Foundation');
ObjC.import('Speech');
var app = Application.currentApplication();
if (!$['SFSpeechRecognitionTaskDelegate']) {
ObjC.registerSubclass({
name: 'SFSpeechRecognitionTaskDelegate',
superclass: 'NSObject',
@SKaplanOfficial
SKaplanOfficial / GetSafariBookmarks.scpt
Created April 14, 2023 13:00
AppleScript to get the list of bookmark URLs from Safari.
use framework "Foundation"
(*
Gets a record of information contain in a plist file.
Params:
thePath (String) - Path to the plist file.
Returns:
(Record) - The property:value pairs in the plist.
@SKaplanOfficial
SKaplanOfficial / FloatingRaycastWindow.tsx
Created April 6, 2023 21:51
Raycast command that uses AppleScriptObjC to create a floating window.
import { closeMainWindow } from "@raycast/api"
import { runAppleScript } from "run-applescript"
const displayWindow = async () => {
console.log(await runAppleScript(`use framework "Foundation"
use scripting additions
set theWindow to missing value
-- Can only display windows on the main thread
my performSelectorOnMainThread:"showWindow" withObject:(missing value) waitUntilDone:true
@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 / 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 / ToggleStageManager.scpt
Created April 4, 2023 06:13
AppleScript script to toggle stage manager in MacOS Ventura.
tell application "System Events"
set theProcess to first application process whose name is "ControlCenter"
click menu bar item 2 of menu bar 1 of theProcess
perform action 1 of button 1 of group 1 of window 1 of theProcess
end tell
@SKaplanOfficial
SKaplanOfficial / FlipPDFHorizontally.scpt
Created April 2, 2023 08:33
AppleScriptObjC script to flip each page of a PDF horizontally using PDFKit.
use framework "Foundation"
use framework "PDFKit"
-- Load the PDF file as NSData
set thePDFFile to "/Users/exampleUser/Documents/example.pdf"
set pdfData to current application's NSData's dataWithContentsOfFile:thePDFFile
-- Create a PDFDocument from the PDF data
set pdfDoc to current application's PDFDocument's alloc()'s initWithData:pdfData
@SKaplanOfficial
SKaplanOfficial / QueryChatGPT.scpt
Created March 24, 2023 17:49
AppleScriptObjC script to query ChatGPT using NSURLRequest and NSJSONSerialization.
use framework "Foundation"
property ca : current application
set theResult to ""
on queryChatGPT(query, openAIKey)
global theResult
set APIEndpoint to "https://api.openai.com/v1/chat/completions"
set theURL to ca's NSURL's URLWithString:APIEndpoint