Mail Folder Export as a Text File

Here’s the actual script with feed I’m using:

set TID to AppleScript's text item delimiters
set {startTitles, endTitles} to {{}, {}}

set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "Temp Export Folder" as text)
do shell script "mkdir -p " & FolderLocdo

set xxx to do shell script "curl [url=http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true]http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true"[/url]

set AppleScript's text item delimiters to {"<item><title>", "</title></item>"}
set xxx to text items 2 thru -2 of xxx
repeat with aTitle in xxx
	if aTitle's contents is not "" then set end of endTitles to aTitle's contents
end repeat

set text item delimiters to "." & return
set endTitles to endTitles as text
set AppleScript's text item delimiters to TID

do shell script "echo " & quoted form of endTitles & " > " & FolderLocdo & "/test.txt"

Thanks,

Carl

Systems before Snow Leopard do not support multiple text item delimiters.
Try this:


set TID to AppleScript's text item delimiters
set {startTitles, endTitles} to {{}, {}}

set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "Temp Export Folder" as text)
do shell script "mkdir -p " & FolderLocdo

set xxx to do shell script "curl [url=http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true]http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.npr.org%2Frss%2Frss.php%3Fid%3D1001%22&diagnostics=true"[/url]

set AppleScript's text item delimiters to "<item><title>"
set xxx to text items 2 thru -2 of xxx
set AppleScript's text item delimiters to {""}
set xxx to xxx as text
set AppleScript's text item delimiters to "</title></item>"
set xxx to text items of xxx

repeat with aTitle in xxx
	if aTitle's contents is not "" then set end of endTitles to aTitle's contents
end repeat

set text item delimiters to ". " & return
set endTitles to endTitles as text
set AppleScript's text item delimiters to TID

do shell script "echo " & quoted form of endTitles & " > " & FolderLocdo & "/test.txt"

Perfect! Thanks a bunch for all your help.

Thanks,

Carl

When I test this link on the YQL RSS Console site it doesn’t return any useful results that I can plug into the script
we’ve been working on in this thread.

feed://www.jokesareawesome.com/rss/random/

Just would like to download the random joke that’s posted there for my HA system to read.
Any thoughts on that?

Thanks,

Carl

Try:
select title from rss where url=“http://www.jokesareawesome.com/rss/random/

That returns:

<?xml version="1.0" encoding="UTF-8"?>



true

249
247
28595






Still no whole joke.

Thanks,

Carl

You started the thread asking for titles. If you want the whole feed your YQL statement would start with select * rather than select title. From there, it is just a matter of extracting the text you want by manipulating text item delimiters. Here is a good tutorial: http://macscripter.net/viewtopic.php?id=24656 Try working through it so you can tackle the next one yourself.

set TID to AppleScript's text item delimiters

set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "Temp Export Folder" as text)
do shell script "mkdir -p " & FolderLocdo

set xxx to do shell script "curl [url=http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.jokesareawesome.com%2Frss%2Frandom%2F%22&format=json&callback=cbfunc]http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.jokesareawesome.com%2Frss%2Frandom%2F%22&format=json&callback=cbfunc"[/url]

set AppleScript's text item delimiters to "[CDATA["
set xxx to text items 3 thru -1 of xxx
set AppleScript's text item delimiters to {""}
set xxx to xxx as text
set AppleScript's text item delimiters to "]]>"
set xxx to text item 1 of xxx

set AppleScript's text item delimiters to TID
do shell script "echo " & quoted form of xxx & " > " & FolderLocdo & "/test.txt"

Thanks again for all your help, I will definitely be digging into that tutorial. Biggest issue for me is editing
out the coding etc.

My first project will be this one, getting out the breaks.

Two ships were at sea, a British one and a German one. Suddenly the British ship malfunctioned and they were going down

So they radioed the Germans and said" mayday mayday. We’re sinking!!"



Some time lapsed and the Germans replied, “what are you s-thinking about?”

Thanks again!

Carl

P.S. Hope it’s other jokes are better than this one.

Happy to help.

set theString to "ABC"

-- Break apart
set AppleScript's text item delimiters to "B"
set xxx to text items of theString

-- put together
set AppleScript's text item delimiters to {""}
set xxx to xxx as text

That’s a terrific example. It’s easy to perform edits, but for the life of me I’m not getting how to incorporate
them into the existing script. Is there a more basic step by step for this type of editing you may know of?

This one replaces the
with a space, which I find I need to do with some other characters as well.

set theString to "D<br />K"

-- Break apart
set AppleScript's text item delimiters to "<br />"
set xxx to text items of theString

-- put together
set AppleScript's text item delimiters to {" "}
set xxx to xxx as text

Thanks,

Carl

You don’t need to set theString to anything because xxx is already defined. Try to remove the first line and change

set xxx to text items of theString

to

set xxx to text items of xxx

then add your script below

set AppleScript's text item delimiters to "]]>"
set xxx to text item 1 of xxx

Gotcha, many thanks again. Still learning…actually got it to remove the
thing last night with some trial and error.

Carl

I have tried modifying the selection portion.
I am trying to write out a text file of only the messages selected, and not the entire mailbox

The following is the latest and a few commented lines to show what I have tried, so far I keep getting class errors.

Anyone see the problem?


--set TID to AppleScript's text item delimiters
set endSubjects to {}

set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "Temp Export Folder" as text)
do shell script "mkdir -p " & FolderLocdo

tell application "Mail"
	--tell mailbox "Inbox" of account 1
	set theMessages to selected messages of message viewer 1
	--set theSubjects to subject of (items of theMessages)
	set theSubjects to subject of it's message
	--set theSubjects to subject of (text items of theMessages) as rich text
	--end tell
end tell

repeat with eachMessage in theMessages
	--set theTitles to subject of it's message of theMessages
	--end tell
	--repeat with myTitle in theTitles
	--set AppleScript's text item delimiters to {".", ",", "/", ":", "[", "]"}
	set theSubjects to text items of eachMessage
	set AppleScript's text item delimiters to {""}
	set theSubject to theSubject as text
	--if (count of characters of theTitle) > 32 then set theTitle to text 1 thru 32 of theTitle
	set end of endSubjects to theSubject
end repeat




set text item delimiters to return
set endSubjects to endSubjectss as text
--set AppleScript's text item delimiters to TID

do shell script "echo " & quoted form of endSubjectss & " > " & FolderLocdo & "/test.txt"

This is the solution I was seeking:


set endTitles to {}

set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "Temp Export Folder" as text)
do shell script "mkdir -p " & FolderLocdo

tell application "Mail"
	activate
	set theSelectedMessages to selection
	set theMessages to theSelectedMessages
	repeat with eachMessage in theMessages	
		tell eachMessage	
			if sender is "sender@some.com" then		
				set theSubject to subject
				set end of endTitles to theSubject as Unicode text	
			end if
		end tell
	end repeat
end tell

set text item delimiters to return
set endTitles to endTitles as Unicode text

do shell script "echo " & quoted form of endTitles & " > " & FolderLocdo & "/test.txt"