Skip to main content

02 appleScript基础知识

1 什么是AppleScript?​

AppleScript是一种用于mac OS的自动化操作语言。

2 常用示例​

2.1 获取当前激活的应用名​

tell application "System Events"
set frontmostProcess to first process where it is frontmost
set appName to name of frontmostProcess
end tell
display dialog (appName)

2.2 指定应用执行javascript​

tell application "Google Chrome"
execute front window's active tab javascript "document.querySelector('video').paused ?document.querySelector('video').play() : document.querySelector('video').pause()"
end tell

2.3 激活应用​

tell application "Google Chrome" to active

2.4 退出应用​

tell application "Activity Monitor"
quit
end tell

//:xxx todo 省略10万字,后面再说

参考文献​

官方文档 官方新手教程