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
| public extension NSImage { | |
| /// Initializes and returns a new color swatch image. | |
| /// - Parameters: | |
| /// - color: The fill color of the image. | |
| /// - size: The width and height of the image. | |
| convenience init(color: NSColor, size: NSSize) throws { | |
| self.init(size: size) | |
| guard let ciColor = CIColor(color: color) else { | |
| assertionFailure("Could not create CIColor from NSColor") |
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
| defaults -currentHost write -globalDomain NSStatusItemSpacing -int 6 | |
| defaults -currentHost write -globalDomain NSStatusItemSelectionPadding -int 6 | |
| killall ControlCenter |
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
| (() => { | |
| ObjC.import('objc'); | |
| ObjC.import('AppKit') | |
| // Get methods of ObjC class, store # of methods and properties in reference objects | |
| const targetClass = $.NSImage; | |
| const num_methods = Ref(); | |
| const num_properties = Ref(); | |
| const methods = $.class_copyMethodList(targetClass, num_methods); | |
| const properties = $.class_copyPropertyList(targetClass, num_properties) |
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
| 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); |
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
| function performMailActionWithMessages(messages, options) { | |
| // do stuff, e.g.: | |
| const app = Application('System Events'); | |
| app.includeStandardAdditions = true; | |
| // messages are provided as a list | |
| app.displayDialog(messages.map((message) => message.subject()).join(', ')) | |
| // options are provided as an object with two properties: inMailboxes and forRule | |
| // both options can be undefined |
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
| use framework "Foundation" | |
| property ca : current application | |
| property theResult : "" | |
| property query : missing value | |
| try | |
| set result to "" | |
| ca's NSNotificationCenter's defaultCenter's addObserver:me selector:"queryDidFinish:" |name|:"NSMetadataQueryDidFinishGatheringNotification" object:(missing value) | |
| set predicate to ca's NSPredicate's predicateWithFormat:"kMDItemContentType == 'com.apple.application-bundle'" |
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
| 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'); |
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
| (() => { | |
| 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; |
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
| // Reference: https://developer.apple.com/documentation/avfaudio/avaudiorecorder?language=objc | |
| (() => { | |
| ObjC.import("objc"); | |
| ObjC.import("AVFoundation"); | |
| const outputURL = $.NSURL.alloc.initFileURLWithPath("/Users/exampleUser/Downloads/test.mp4"); | |
| const settings = $.NSMutableDictionary.alloc.init | |
| settings.setValueForKey($.kAudioFormatAppleIMA4, $.AVFormatIDKey) | |
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
| (() => { | |
| ObjC.import("CoreGraphics"); | |
| const windowList = ObjC.castRefToObject($.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID)) | |
| const raycastWindow = windowList.js.find((win) => win.allKeys.containsObject("kCGWindowIsOnscreen") && win.js["kCGWindowLayer"].js == 8 && win.js["kCGWindowOwnerName"].js == "Raycast") | |
| return raycastWindow != undefined | |
| })() |