J. Tuttle,
Sure, but you may have to do some slight modifications for your own purposes. First, the script requires that you have mail running on whatever system you use for storing your iTunes downloads. Second, my script gets my iTunes password from the OSX keychain in the event that iTunes asks for it before downloading (it doesn't always ask for the password, but I would rather that the script could get it if it happens so that my new episodes are downloaded when I come home from work). To do this, I have created a new item in the Login keychain called "iTunes Login" and put my iTunes password there. You can access keychain items from applications-->utilities-->keychain access. You could also just put your password directly in the script instead of getting it from the keychain, but this would be storing your password in plaintext.
The last thing is that I have a mail rule to run this: if sender contains do_not_reply@itunes.com AND subject contains available
Run Applescript - Get Available Purchases 3.0
I haven't been able to test this for more than 2 episodes, so I don't know if it is perfect yet, but it seems to work great at this point in time (it will probably continue working until Apple again changes the download functionality... this is my 3rd version of the script). There are some built-in delays to ensure a successful download. It takes about 30 seconds for the script to run completely.
Here it is - Get Available Purchases 3.0
using terms from application "Mail"
on perform mail action with messagestheMessages
repeat with eachMessage in theMessages
getEpisode(eachMessage)
end repeat
end perform mail action with messages
end using terms from
on getEpisode(eachMessage)
tell application "Mail"
set myMessage to source of eachMessage
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()
end if
end if
end tell
end getEpisode
on fixTheText(someText)
set someText to someText as text
tell application "Finder"
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'")
end tell
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
delay 10
if button "Download" of window 1 exists then
click button "Download" of window 1
end if
set keepgoing to "true"
repeat until keepgoing is equal to "false"
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
keystrokereturn
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