使用 AppleScript 解析 RSS(使用 grep?)
Parse RSS with AppleScript (using grep?)
我正在尝试编写一个 AppleScript 来将我的桌面背景设置为当天最新的 NASA 图片。我正在尝试使用此 RSS 提要来执行此操作:https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss
最后一块拼图是从 rss 提要中解析图像的 URL。我认为这应该很可能使用 grep,但我不知道如何使用 grep。我确实看了提要,我知道我想要的URL将是第一个<item>
中的第一个<link>
。
set {year:y, month:m, day:d} to (current date)
set todaydate to d & "\ " & m & "\ " & y
log todaydate
set myFile to "/Users/me/Pictures/NASA\ Image\ of\ the\ Day/" & todaydate & ".jpg"
property RSSURL : "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss"
--get the first download link from the rss feed
--ie stuff inside <link> </link> directly after first <item>
set pictureURL to "" --but to the right thing, of course
do shell script "curl -o " & myFile & " " & pictureURL
tell application "Finder" to set desktop picture to POSIX file "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
我正在尝试编写一个 AppleScript 来将我的桌面背景设置为当天最新的 NASA 图片。我正在尝试使用此 RSS 提要来执行此操作:https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss
最后一块拼图是从 rss 提要中解析图像的 URL。我认为这应该很可能使用 grep,但我不知道如何使用 grep。我确实看了提要,我知道我想要的URL将是第一个<item>
中的第一个<link>
。
set {year:y, month:m, day:d} to (current date)
set todaydate to d & "\ " & m & "\ " & y
log todaydate
set myFile to "/Users/me/Pictures/NASA\ Image\ of\ the\ Day/" & todaydate & ".jpg"
property RSSURL : "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss"
--get the first download link from the rss feed
--ie stuff inside <link> </link> directly after first <item>
set pictureURL to "" --but to the right thing, of course
do shell script "curl -o " & myFile & " " & pictureURL
tell application "Finder" to set desktop picture to POSIX file "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