I have a feeling that it will be that way for at least a little while. It is just the way the download system works. AppleTV requires users to "buy" free episodes. And now the iTunes prompt has a "download" button for the first prompt, then if user hasn't logged into the store recently a username and password prompt comes up with a button to "buy" the free episode. Before the most recent update, sending keystroke return would work, but, as of now, the "buy" button must be clicked.
I don't have any new episdoes for about 6 days, but I think the following script should take care of everything. I also made a change so that it only runs on new (unread) mail, so when manually using the right-click menu to apply rules it won't download every episode unless you mark the message as unread first.
using terms from application "Mail"
on perform mail action with messagesmessageList
repeat with currentMessage in messageList
if read status of currentMessage is false then
getEpisode(currentMessage)
end if
end repeat
end perform mail action with messages
end using terms from
on getEpisode(theMessage)
tell application "Mail"
set myMessage to source of theMessage
set start to offset of "https://buy.itunes.apple.com/" in myMessage
if start ≠ 0 then
set theLength to length of myMessage
set addr to characters start through theLength of myMessage as string
set addyEnd to offset of "&mt=" in addr
set addyEnd to addyEnd + 7
set addr to characters 1 through addyEnd of addr as string
if length of addr > 7 then
tell me to set fixedAddress to fixTheText(addr)
my openWeb(fixedAddress)
my iTunesDL()
set read status of theMessage to true
end if
end if
end tell
end getEpisode
on fixTheText(someText)
set someText to do shell script ("echo " & quoted form of someText & " | sed 's/=3D/@/g'")
delay 0.5
set someText to do shell script ("echo " & quoted form of someText & " | sed 's/=//g'")
delay 0.5
set someText to do shell script ("echo " & quoted form of someText & " | sed 's/@/=/g'")
set theLines to TextToList(someText, return)
set trimChars to {" ", ASCII character 9}
repeat with aLine in theLines
set lineLen to length of aLine
set startPos to 1
set foundEOFwd to false
repeat while not foundEOFwd and startPos ≤ lineLen
set theChar to textstartPos thru startPos of aLine
if not (trimChars contains theChar) then
set foundEOFwd to true
else
set startPos to startPos + 1
end if
end repeat
set contents of aLine to text startPos thru -1 of aLine
set endPos to length of aLine
set foundEOFwd to false
repeat while not foundEOFwd and endPos ≥ 1
set theChar to textendPos thru endPos of aLine
if not (trimChars contains theChar) then
set foundEOFwd to true
else
set endPos to endPos - 1
end if
end repeat
set contents of aLine to text 1 thru endPos of aLine
end repeat
set someText to ListToText(theLines, "")
return (someText)
end fixTheText
on TextToList(theText, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theList to every text item of theText
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStrnumbererrNum
end try
set AppleScript's text item delimiters to saveDelim
return (theList)
end TextToList
on ListToText(theList, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theText to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStrnumbererrNum
end try
set AppleScript's text item delimiters to saveDelim
return (theText)
end ListToText
on openWeb(pageAddress)
tell application "Safari"
open locationpageAddress
end tell
end openWeb
on iTunesDL()
activateapplication "iTunes"
tell application "System Events" to tell process "iTunes"
activate
set windowFound to false
repeat until windowFound
delay 2
activate
if button "Download" of window 1 exists then
click button "Download" of window 1
set windowFound to true
end if
end repeat
set keepgoing to true
repeat until not keepgoing
delay 10
if text field 2 of window 1 exists then
tell me to set passwd to getPW("iTunes Login")
set value of text field 2 of window 1 to passwd
click button "Buy" of window 1
else
set keepgoing to false
end if
end repeat
end tell
end iTunesDL
on getPW(searchName)
do shell script "security 2>&1 >/dev/null find-generic-password -gs " & quoted form of searchName & " | awk '{print $2}'"
return (text 2 thru -2 of result)
end getPW