官方文档

Introduction to AppleScript Language Guide

快速使用

AppleScript 入门:探索 macOS 自动化

效率提升:使用AppleScript模拟鼠标键盘操作制作自动化工具 - GCS_DEVELOPER的个人空间 - OSCHINA

Mac App UI 元素的定位

手把手教你用 AppleScript 模拟鼠标键盘操作,实现 macOS 系统的自动化操作

示例脚本

有道云音乐自动打开关闭脚本

--有道云音乐自动打开关闭脚本

set procPath to "/Applications/NeteaseMusic.app" --程序路径
set procName to "NeteaseMusic" --程序进程名称

tell application "System Events"
	tell process procName
		set isRunning to exists --程序运行状态
		set isOpen to exists (window 1) --主窗口窗口打开状态
	end tell
end tell

if not isRunning then
	--运行程序
	tell application procPath to activate
else if not isOpen then
	--运行、程序主窗口不可见,打开程序主窗口
	tell application procPath to reopen
else
	--运行、	程序主窗口可见,关闭程序主窗口
	tell application "System Events"
		click button 1 of window 1 of process procName
	end tell
end if

获取程序 UI 元素

tell application "System Events"
	tell process "Notion"
		entire contents
	end tell
end tell

调试输出