示例

1import { Script } from "scripting"
2
3async function run() {
4  console.present().then(() => {
5    Script.exit()
6  })
7
8  console.log("Start to fetch contacts")
9  try {
10    const contacts = await Contact.fetchAllContacts()
11
12    const first = contacts.at(0)
13
14    if (!first) {
15      console.log("No contacts found")
16    } else {
17      console.log("There are " + contacts.length + " contacts")
18
19      const name = [
20        first.givenName,
21        first.familyName
22      ].join(" ")
23      
24      console.log("First contact name: " + name)
25    }
26  } catch (e) {
27    console.error(e)
28  }
29}
30
31run()