注释
#!/usr/bin/osascript
(**)
词汇约定
# 方式一set myName to "Davied"# 方式二copy 18 to age
# 字符串"Daived"# 布尔值true false# 常量pi# 列表{1,"name",true}# 数字1# 无序集合{name:"Daived",age:10}
10 * 1001 + 1024
# 华氏度 53set averageTemp to 53 as degrees Fahrenheit
# 可以包裹其他语句# 告诉Finder应用tell application "Finder"# 设置第一窗口名称到变量set saveName to name of front window# 关闭窗口close window saveNameend tell
# 获取窗口名称 告诉前台窗口 告诉Chrome应用get name of front window of application "Chrome"
基础知识
:::info 脚本对象是指包含以下特性的脚本
定义Handler
on greetClient(nameOfClient) set res to display dialog (“Hello “ & nameOfClient & “!”) end greetClient
定义Script
script testGreet greetClient(defaultClientName) end script
运行Script
run testGreet
<a name="AItXA"></a>## 控制语句---<a name="jls7F"></a>### 判断```sqlset name to "Dong"if name is not equal to "Daived" then say "错误的名字"
遍历
set i to 1repeatif i > 2 then exit repeatset i to i + 1say iend repeat
set users to {"Daived","Bob"}repeat with user in userssay userend repeat
运算符
常用命令
set … to …
给一个或者多个变量设置值
set msg to "hello"
set intList to {1,2,3}set item 2 of intList to 12
activate …
打开应用,并置顶窗口
activate application "Google Chrome"
tell application "Google Chrome" to activate,
