| title | updated | layout | category | prism_languages | intro | |
|---|---|---|---|---|---|---|
AppleScript |
2023-04-05 |
2017/sheet |
macOS |
|
AppleScript is a scripting language for automating macOS. |
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() { | |
| 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'); |
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
| 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 |
Outline paths can be significantly more performant than AppleScript's filtering operations.
For example, //*/run::@strong gets interpreted as:
- For all descendants of the root node,
- Look at their associated rich text by using run:: axes, then
- Run predicate against the attributes associated with each rich text run’s attributes.
Within Bike, outline paths can return different kinds of values:
| 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. |
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
| import Cocoa | |
| @objc | |
| class SomeTextStorage: NSTextStorage { | |
| private var storage: NSMutableAttributedString | |
| override init() { | |
| storage = NSMutableAttributedString(string: "", attributes: nil) | |
| super.init() |
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
| 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'); |
NewerOlder