1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
beep 2
# 哔两次
display dialog myString
# 弹出框
set theLength to the length of "Neal"
# 获取字符串的长度
set strToNumber to "16" as number
set numToStr to 12 as string
# 类型转换
set exampleList to {1,2,3,"hahah",9}
#定义数组,数组元素的index从1开始
set addToBegin to {"winter"}
set addToEnd to {"summer", "autumn"}
set currentList to {"spring"}
set modifiedList to addToBegin & currentList & addToEnd
# 数组拼接
set testList to {"Neal", "haha"}
set item 2 of testList to "yang"
get testList
# 变更数组元素。输出 {"Neal", "yang"}
set myList to {"neal", "haha"}
set valueOfLastItem to item -1 of myList
# 通过index获取数组元素,index为负数代表从右往左取。
set myList to {"a", "b", "c", "d", "e", "f"}
set shortList to items 2 through 5 of myList
# 通过index的区间取多个数组元素
set reversedList to reverse of {2, 3, 4, 6, 7}
# reverse数组倒序
set theListLength to the count of {"ds", 1, 2, 3}
# count或length获取数组长度
set x to some item of {1, 2, 3, 4, 5, 7, 7, 6, 5}
# some随机获取数组元素
set itemized to every character of "Nealyang"
get itemized
# every character of 将字符串转成字符数组
set myString to "neal's personal website is www.nealyang.cn"
set oldDelimiters to AppleScript's text item delimiters #保持原单词分割符
set AppleScript's text item delimiters to " " #定义单词分割符为空格
set myList to every text item of myString
set AppleScript's text item delimiters to oldDelimiters #恢复原单词分割符
get myList
# every text item of 将字符串用分割符转成字符串数组
set man to {name:"yang", age:13}
set manName to name of man
get manName
# 对象的定义和取值
set stringToBeDisplayed to "Neal is pretty boy"
set tempVar to display dialog stringToBeDisplayed buttons {"So,so", "Don't know", "yes"}
set theButtonPressed to button returned of tempVar
display dialog "You pressed the following button " & theButtonPressed
# 弹出框取得点击的按钮
|