Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / SummarizeText.js
Created May 25, 2023 01:59
JXA script to summarize text using SKSummary from the CoreServices framework.
(() => {
ObjC.import("CoreServices")
const unsummarizedText = `Inventore eveniet eum veritatis inventore necessitatibus provident. Sit reprehenderit non ad. Blanditiis impedit sapiente. Incidunt harum neque commodi rerum nobis dolor aliquam. Ipsam consequatur distinctio ratione veniam hic. Possimus iure molestiae tempore cumque reiciendis repudiandae quibusdam.`
const numOutputSentences = 3
const CFStringRef = $.CFStringCreateWithCString(null, unsummarizedText, $.kCFStringEncodingMacRoman)
const summaryObj = $.SKSummaryCreateWithString(CFStringRef)
const summaryText = ObjC.castRefToObject($.SKSummaryCopySentenceSummaryString(summaryObj, numOutputSentences)).js
return summaryText
@SKaplanOfficial
SKaplanOfficial / GetFirstFrameOfVideo.scpt
Created May 25, 2023 01:33
JXA script to extract the first frame of a video and save it into a TIFF file.
(() => {
ObjC.import("objc");
ObjC.import("CoreMedia");
ObjC.import("Foundation");
ObjC.import("AVFoundation");
ObjC.import("CoreGraphics");
ObjC.import("CoreImage");
ObjC.import("AppKit");
const outputPath = "/Users/example/Downloads/example.tiff"
@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