AppleScript备忘单
¶代码片段
获取某进程的所有UI元素
1 | tell application "System Events" to tell process "_进程名称_" |
判断应用窗口是否在前台;如是,则将其隐藏
1 | if application "_应用名称_" is frontmost then |
通过Alfred实现GoldenDict一键查词
1 | on alfred_script(selected_text) |
在通知中心显示通知
1 | display notification "通知内容" with title "通知标题" subtitle "通知副标题" |
显示对话框
1 | -- `¬`表示此处非换行 |
获取应用「Bundle ID」
1 | osascript -e 'id of app "$applicationName"' |
¶参考资料
- Apple. Mac Automation Scripting Guide.
- Apple. AppleScript Language Guide.
- Christopher Kielty. Complete List of AppleScript Key Codes.
- Gary Rosenzweig. Automator and AppleScript Tutorials.
- 陈德. AppleScript快速入门.
- 少数派. 快速上手macOS GUI Scripting:基于UI元素的系统自动化控制.
¶商业产品
- Bill Cheeseman. UI Browser by PFiddlesoft.
- Doug Adams. Doug’s AppleScripts.
¶JXA (JavaScript for Automation)
- Angelina Fabbro. OSX Automation Using JavaScript.
- Github. JavaScript for Automation Cookbook.
- Groups.io. JXA Resources.