Example

1import { Script } from "scripting"
2
3console.present().then(() => {
4  Script.exit()
5})
6
7console.log("Requesting Current Weather...")
8
9async function displayCurrentWeather() {
10  let location: LocationInfo | null = null
11  try {
12    console.log("Requesting location... Please move your device to trigger a location update.")
13    location = await Location.requestCurrent()
14
15    if (location) {
16      const placemarks = await Location.reverseGeocode(location)
17      if (placemarks && placemarks.length) {
18        console.log(`Your current location: ${JSON.stringify(placemarks[0], null, 2)}`)
19      }
20    }
21  } catch (e) {
22    console.log("Failed to request location", e)
23  }
24
25  if (!location) {
26    console.error("Please approval the location permission request")
27    return
28  }
29
30  // Use the WeatherKit
31  const weather = await Weather.requestCurrent(
32    location
33  )
34
35  console.log(
36    `The temperature is ${weather.temperature.formatted
37    } with ${weather.condition}`
38  )
39}
40
41displayCurrentWeather()