Overall goal:
OS X Service which adds spoken versions of all unread email in the Mail.app inbox to iTunes with email metadata (subject, sender, date, content) as track info.
Gist of workflow:
-Get new mail
-Get inbox messages → Filter to unread only → Set storage variable “unreadMail” for later access by AppleScript #2
-Run AppleScript #1 to create the text that will be spoken
-Text to Audio → Import to iTunes as AAC → Set iTunes info that is common to all → Set iTunes options → Add songs to playlist
-Run AppleScript #2 to set iTunes info that is unique to each message (subject, sender, date, content)
The problem:
Only works when run in the Automator application. When run as a service in Apple Mail, AppleScript #2 gets an error. My guess is that it can’t access the workflow’s “unreadMail” storage variable. I could add a “Get variable value” as the input to AppleScript #2, but then it would lose access to the iTunes tracks. I need AppleScript #2 to access both the input from the previous action (the iTunes tracks) and the workflow variable.
Current input for AppleScript #2 is the track info
on run {input, parameters}
set i to 1
repeat with eachTrack in input
get value of variable "unreadMail" of front workflow
set everyMsg to result
set thisMsg to item i of everyMsg
tell application "Mail"
set msgContent to content of thisMsg
set msgDate to date received of thisMsg
set msgSender to (extract name from sender of thisMsg)
set msgSubject to subject of thisMsg
end tell
tell application "iTunes"
tell eachTrack to set {artist, comment, lyrics, name} to {msgSender, "Email received: " & msgDate, msgContent, msgSubject}
end tell
set i to (i + 1)
end repeat
end run
Model: MacBook Pro
AppleScript: 2.1.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)