Some Apple and third-party applications are written with AppleScript scripting dictionaries incorporated within the App bundle for the purpose of controlling that application with certain AppleScript reserved words. Some of these dictionaries are robust (e.g. MS Word) and some limited (e.g. Apple's Preview). If you open a blank Script Editor document and subsequently use the File menu > Open Dictionary… you will see a list of those applications.
If you have done any AppleScript-based GUI scripting, that is very fragile to future application interface design changes which Apple is constantly revisiting. Caveat emptor.
Apple introduced JavaScript for Automation (JXA) that is also supported in the Script Editor. Apart from specific application scripting dictionary support for JXA, there is limited documentation available for it from Apple, and one learns by web searching for what others have done. Unlike AppleScript, JXA supports the full scripting bridge so you can use Classes from CoreGraphics, CoreFoundation, and other Frameworks directly.
Apple is doing very little to improve AppleScript or JXA support and I would not depend upon scripts these languages for long-term Apple automation support. Apple is moving away from Automator to its Shortcuts solution.
Apple's Foundation Framework includes the NSAppleScript Class. One can use that to run AppleScript from Objective-C, Swift, or even Python 3 (with current PyPy pyobjc package).
Here is Swift 6 getting the current (this post) tab URL from Safari 18.5 in Sequoia v15.5:
#!/usr/bin/swift
import Foundation
var error: NSDictionary?
let browserTab = "tell application \"Safari\" to get URL of current tab of window 1"
let scriptObject = NSAppleScript(source: browserTab)!
let outURL: NSAppleEventDescriptor = scriptObject.executeAndReturnError(&error)
guard error == nil else {
fatalError("AppleScript flaw or Safari not running.")
}
print(outURL.stringValue!)
chmod +x ./test.swift
./test.swift
https://discussions.apple.com/thread/256081580?sortBy=oldest_first