2019-03-12 04:37:49 +00:00
|
|
|
|
# osascript
|
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
> 在命令行中运行指定的 AppleScript 或 JavaScript 脚本程序。
|
2024-01-31 10:20:27 +00:00
|
|
|
|
> 更多信息:<https://keith.github.io/xcode-man-pages/osascript.1.html>.
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 运行一个 AppleScript 命令:
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2024-01-01 09:38:53 +00:00
|
|
|
|
`osascript -e "{{say '你好世界'}}"`
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 运行多条 AppleScript 命令:
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2024-01-01 09:38:53 +00:00
|
|
|
|
`osascript -e "{{say '你好'}}" -e "{{say '世界'}}"`
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 运行一个已编译的脚本(`*.scpt`),包脚本(`*.scptd`),或明文的(`*.applescript`)AppleScript 文件:
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2019-10-20 03:34:33 +01:00
|
|
|
|
`osascript {{目录 / 脚本文件.scpt}}`
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 获取应用程序的包名(这个包名,可以用在命令 `open -b` 中):
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
|
|
|
|
`osascript -e 'id of app "{{应用程序名}}"'`
|
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 运行一个 JavaScript 命令:
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2024-01-01 09:38:53 +00:00
|
|
|
|
`osascript -l JavaScript -e "{{console.log('你好世界!');}}"`
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 运行 JavaScript 文件:
|
2019-03-12 04:37:49 +00:00
|
|
|
|
|
2019-10-20 03:34:33 +01:00
|
|
|
|
`osascript -l JavaScript {{路径 / 文件名.js}}`
|