Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / WifiControl.scpt
Created March 24, 2023 04:56
AppleScriptObjC script containing functions to interact with the WiFi interface via the CoreWLAN framework.
use framework "CoreWLAN"
set knownNetworkNames to {}
set theClient to my CWWiFiClient's sharedWiFiClient()
theClient's setDelegate:me
-- Get main WiFi interface
set theWiFiInterface to theClient's interface()
on disconnect()
@SKaplanOfficial
SKaplanOfficial / GetQRPayload.scpt
Created March 23, 2023 19:24
AppleScriptObjC script to get the payload value of QR codes in images.
use framework "CoreImage"
on getQRPayload(imagePath)
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
set theCIImage to current application's CIImage's imageWithData:(theImage's TIFFRepresentation())
set theDetector to my (CIDetector's detectorOfType:(my CIDetectorTypeQRCode) context:(my CIContext's context()) options:(missing value))
set theFeatures to theDetector's featuresInImage:theCIImage
set theResult to ""
@SKaplanOfficial
SKaplanOfficial / GetSymbolDataURI.scpt
Created March 23, 2023 17:43
AppleScriptObjC script to get the image/png data URI of a built-in system symbol.
use framework "AppKit"
on getDataURIForImage:theNSImage
-- Gets the image/png data URI of an NSImage
set theTIFFData to theNSImage's TIFFRepresentation()
set theBitmap to my (NSBitmapImageRep's imageRepWithData:(theTIFFData))
set thePNGData to theBitmap's representationUsingType:(my NSJPEGFileType) |properties|:(missing value)
return "data:" & "image/png" & ";base64," & (thePNGData's base64EncodedStringWithOptions:0) as text
end getDataURIForImage:
@SKaplanOfficial
SKaplanOfficial / GetAllContactData.scpt
Created March 23, 2023 02:11
AppleScriptObjC script to get the data of every contact using the Contacts framework.
use framework "Contacts"
set contactStore to my CNContactStore's alloc()'s init()
-- All possible keys
set targetKeys to {my CNContactIdentifierKey, my CNContactTypeKey, my CNContactPropertyAttribute, my CNContactNamePrefixKey, my CNContactGivenNameKey, my CNContactMiddleNameKey, my CNContactFamilyNameKey, my CNContactPreviousFamilyNameKey, my CNContactNameSuffixKey, my CNContactNicknameKey, my CNContactPhoneticGivenNameKey, my CNContactPhoneticMiddleNameKey, my CNContactPhoneticFamilyNameKey, my CNContactJobTitleKey, my CNContactDepartmentNameKey, my CNContactOrganizationNameKey, my CNContactPhoneticOrganizationNameKey, my CNContactPostalAddressesKey, my CNContactEmailAddressesKey, my CNContactUrlAddressesKey, my CNContactInstantMessageAddressesKey, my CNContactPhoneNumbersKey, my CNContactSocialProfilesKey, my CNContactBirthdayKey, my CNContactNonGregorianBirthdayKey, my CNContactDatesKey, my CNContactNoteKey, my CNContactImageDataKey, my CNContactThumbnailImageDataKey, my CNContactImageDataAvailableKey,
@SKaplanOfficial
SKaplanOfficial / GetURLHTML.scpt
Created March 22, 2023 23:32
AppleScriptObjC script to get the HTML from a URL using NSURLSession
use framework "Foundation"
set theResult to ""
on getURLHTML(theURL)
global theResult
set theURL to current application's NSURL's URLWithString:theURL
set theSessionConfiguration to current application's NSURLSessionConfiguration's defaultSessionConfiguration()
set theSession to current application's NSURLSession's sessionWithConfiguration:(theSessionConfiguration) delegate:(me) delegateQueue:(missing value)
set theRequest to current application's NSURLRequest's requestWithURL:theURL
set theTask to theSession's dataTaskWithRequest:theRequest
@SKaplanOfficial
SKaplanOfficial / CurrentLocation.scpt
Created March 22, 2023 17:33
AppleScriptObjC script to get the coordinates of the user's current location
use framework "CoreLocation"
use scripting additions
set theLocation to (missing value)
set maxSeconds to 10
set timeStarted to (current date)
on getCurrentLocation()
global theLocation, maxSeconds, timeStarted
set locationManager to current application's CLLocationManager's alloc()'s init()
@SKaplanOfficial
SKaplanOfficial / ApplyComicCIFilter.scpt
Created March 22, 2023 15:26
AppleScriptObjC script to apply the CIComicEffect CIFilter to an image file
use framework "Foundation"
use framework "Quartz"
on applyComicEffect(sourcePath, destinationPath)
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath
-- Set up the Filter
set filterName to "CIComicEffect"
set theFilter to current application's CIFilter's filterWithName:filterName
theFilter's setDefaults()
@SKaplanOfficial
SKaplanOfficial / ClassifySoundFile.scpt
Created March 19, 2023 02:07
AppleScriptObjC script to classify sounds in sound files using the SoundAnalysis framework.
use framework "SoundAnalysis"
set confidenceThreshold to 0.6 -- Level of confidence necessary for classification to appear in result
set theResult to "" -- Sequence of sound classification labels throughout the sound file's duration
-- Analyze sound file for classifiable sounds
on analyzeSound(filePath)
global theResult
-- Initialize sound analyzer with file
@SKaplanOfficial
SKaplanOfficial / ExtractAnimalLabels.scpt
Last active March 18, 2023 23:17
AppleScriptObjC script to extract labels of animals within images using the Vision framework.
use framework "Vision"
on getImageAnimals(imagePath)
-- Get image content
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
-- Set up request handler using image's raw data
set requestHandler to current application's VNImageRequestHandler's alloc()'s initWithData:(theImage's TIFFRepresentation()) options:(current application's NSDictionary's alloc()'s init())
-- Initialize text request
@SKaplanOfficial
SKaplanOfficial / ExtractImageText.scpt
Created March 18, 2023 22:46
AppleScriptObjC script to extract text from image files using the Vision framework.
use framework "Vision"
on getImageText(imagePath)
-- Get image content
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
-- Set up request handler using image's raw data
set requestHandler to current application's VNImageRequestHandler's alloc()'s initWithData:(theImage's TIFFRepresentation()) options:(current application's NSDictionary's alloc()'s init())
-- Initialize text request