注释
#!/usr/bin/osascript
(*
*)
词汇约定
# 方式一
set myName to "Davied"
# 方式二
copy 18 to age
# 字符串
"Daived"
# 布尔值
true false
# 常量
pi
# 列表
{1,"name",true}
# 数字
1
# 无序集合
{name:"Daived",age:10}
10 * 100
1 + 1024
# 华氏度 53
set averageTemp to 53 as degrees Fahrenheit
# 可以包裹其他语句
# 告诉Finder应用
tell application "Finder"
# 设置第一窗口名称到变量
set saveName to name of front window
# 关闭窗口
close window saveName
end 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>
### 判断
```sql
set name to "Dong"
if name is not equal to "Daived" then say "错误的名字"
遍历
set i to 1
repeat
if i > 2 then exit repeat
set i to i + 1
say i
end repeat
set users to {"Daived","Bob"}
repeat with user in users
say user
end 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,