最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

macos - JQ not recognized by AppleScript - Stack Overflow

programmeradmin9浏览0评论

I have a daily journal I create in Devonthink3, and as part of the note creation, I add that day's weather and the forecast. I ran this fine for about 90 days, but had to wipe the computer and reload the OS, so I'm sure I missed something along the way. I run the script and it throws Failed to parse weather data: sh:jq: command not found

I've installed JSON Helper and of course jq, but I've missed something. I've added the weather portion of the larger script below.

-- Fetch and format weather data
on getWeather()
    set weatherAPIURL to ".json?key=86a511ece53749c88e9205427250301&q=Detroit&days=1&aqi=no&alerts=no"
    try
        set weatherData to do shell script "curl -s " & quoted form of weatherAPIURL
    on error errMsg
        display dialog "Failed to fetch weather data: " & errMsg
        return ""
    end try
    
    try
        set currentTempFt to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.temp_f'"
        set currentCondition to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.condition.text'"
        set currentWindMph to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.wind_mph'"
        set currentWindDir to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.wind_dir'"
        set currentHumidity to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.humidity'"
        set feelslikeF to do shell script "echo " & quoted form of weatherData & " | jq -r '.current.feelslike_f'"
        set forecastCondition to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].day.condition.text'"
        set forecastMaxTempF to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].day.maxtemp_f'"
        set forecastMinTempF to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].day.mintemp_f'"
        set forecastAvgHumidity to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].day.avghumidity'"
        set forecastUV to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].day.uv'"
        set astroSunrise to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].astro.sunrise'"
        set astroSunsetAt to do shell script "echo " & quoted form of weatherData & " | jq -r '.forecast.forecastday[0].astro.sunset'"
        
        set formattedDate to short date string of (current date)
        set formattedTime to time string of (current date)
        
        set output to formattedDate & " " & formattedTime & return & ¬
            "Currently, it's " & currentTempFt & "º, and " & currentCondition & " outside, the wind is " & currentWindMph & " mph from the " & currentWindDir & " and the Humidity is " & currentHumidity & "%. " & ¬
            "Currently, it feels like " & feelslikeF & "º. Today's forecast calls for " & forecastCondition & ", with a high of " & forecastMaxTempF & " ºF and a low of " & forecastMinTempF & " º, today's humidity will be " & forecastAvgHumidity & "%, with a UV index of " & forecastUV & ". " & ¬
            "Sunrise is at " & astroSunrise & " this morning, and Sunset will be at " & astroSunsetAt & " this evening."
        
        return output
    on error errMsg
        display dialog "Failed to parse weather data: " & errMsg
        return ""
    end try
end getWeather
发布评论

评论列表(0)

  1. 暂无评论