Automate tasks using AppleScript and Terminal on Mac — by Apple Support
Short Apple guide on combining AppleScript with Terminal: opening Terminal's scripting dictionary in Script Editor and running an AppleScript file from the command line with osascript.