Macos 使用AppleScript解析RSS(使用grep?)

Macos 使用AppleScript解析RSS(使用grep?),macos,rss,applescript,Macos,Rss,Applescript,我正试图写一个AppleScript,将我的桌面背景设置为当天最新的NASA图像。我正在尝试使用此RSS提要来完成此操作: 最后一个难题是解析rss提要中图像的URL。我认为这应该是非常可能的使用grep,但我不知道如何使用grep。我确实查看了提要,我知道我想要的URL将是第一个中的第一个 将{year:y,month:m,day:d}设置为(当前日期) 将todaydate设置为d&“\\”&m&“\\”&y 今日日志 将myFile设置为“/Users/me/Pictures/NASA\\

我正试图写一个AppleScript,将我的桌面背景设置为当天最新的NASA图像。我正在尝试使用此RSS提要来完成此操作:

最后一个难题是解析rss提要中图像的URL。我认为这应该是非常可能的使用grep,但我不知道如何使用grep。我确实查看了提要,我知道我想要的URL将是第一个
中的第一个

将{year:y,month:m,day:d}设置为(当前日期)
将todaydate设置为d&“\\”&m&“\\”&y
今日日志
将myFile设置为“/Users/me/Pictures/NASA\\Image\\of\\the\\Day/”&todaydate&“.jpg”
属性RSSURL:“https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss"
--从rss提要获取第一个下载链接
--先把东西放进去
将pictureURL设置为“”——当然是正确的
执行shell脚本“curl-o”&myFile&&pictureURL
告诉应用程序“Finder”将桌面图片设置为POSIX文件“myFile”
胜利

set {year:y, month:m, day:d} to (current date)

set todaydate to d & "_" & m & "_" & y
log todaydate

set dir to "~/Pictures/NASA_image_of_the_day/"

set myFile to dir & todaydate & ".jpg"

property RSSURL : "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss"

set XMLfile to dir & "feed.xml"
do shell script "curl -o " & XMLfile & " " & RSSURL

tell application "System Events"
    tell XML file XMLfile
        tell XML element "rss"
            tell XML element "channel"
                tell XML element "item"
                    tell XML element "enclosure"
                        set pictureURL to value of XML attribute "url"
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

--display dialog pictureURL
--display dialog myFile

do shell script "curl -o " & myFile & " " & pictureURL & " -L"

tell application "System Events"
    tell every desktop
        set picture to myFile
    end tell
end tell

用灰色标记是肮脏和错误的。请参阅System Events的XML套件:您应该能够通过引用提取相关值。
set {year:y, month:m, day:d} to (current date)

set todaydate to d & "_" & m & "_" & y
log todaydate

set dir to "~/Pictures/NASA_image_of_the_day/"

set myFile to dir & todaydate & ".jpg"

property RSSURL : "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss"

set XMLfile to dir & "feed.xml"
do shell script "curl -o " & XMLfile & " " & RSSURL

tell application "System Events"
    tell XML file XMLfile
        tell XML element "rss"
            tell XML element "channel"
                tell XML element "item"
                    tell XML element "enclosure"
                        set pictureURL to value of XML attribute "url"
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

--display dialog pictureURL
--display dialog myFile

do shell script "curl -o " & myFile & " " & pictureURL & " -L"

tell application "System Events"
    tell every desktop
        set picture to myFile
    end tell
end tell