Applescript help..... lot's of help.
#1
Scooby Regular
Thread Starter
Join Date: Oct 2004
Location: Was Manc now Camden
Posts: 2,689
Likes: 0
Received 0 Likes
on
0 Posts
Applescript help..... lot's of help.
I really should know more about Applescript, but I have a problem that I think Applescript could easily fix and I don't know where to start with it . I keep telling myself I will learn it but never get the time.
What I would like to do is extract the body text from a batch of email messages from one account and copy it all into a plain text document then remove any instances of the % symbol.
I tried it in Automator but the results aren't great, it keeps the header information which I don't want to display. Here is an example of the automator results so you can at least see the context.
If anyone can help me out I will buy you an ice cream next time I see you
Ta, Andy.
What I would like to do is extract the body text from a batch of email messages from one account and copy it all into a plain text document then remove any instances of the % symbol.
I tried it in Automator but the results aren't great, it keeps the header information which I don't want to display. Here is an example of the automator results so you can at least see the context.
If anyone can help me out I will buy you an ice cream next time I see you
Ta, Andy.
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 23:10:47 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : manchester
Keywords : city centre
Min. Price : 80000
Max. Price : 120000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 23:04:56 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : uttoxeter
Keywords : jayman
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 22:59:33 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : bridlinton
Min. Price : 100000
Max. Price : 200000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 22:59:26 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : temple%cloud
Keywords : rural
Min. Price : 0
Max. Price : 170000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 23:10:47 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : manchester
Keywords : city centre
Min. Price : 80000
Max. Price : 120000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 23:04:56 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : uttoxeter
Keywords : jayman
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 22:59:33 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : bridlinton
Min. Price : 100000
Max. Price : 200000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DATE: Tue, 28 Jun 2005 22:59:26 +0200
SENDER: HomeInfo <donotreply@homeinfo.co.uk>
SUBJECT: Search at HomeInfo.co.uk
RECIPIENT: backup@homeinfo.co.uk
Guest User search at HomeInfo.co.uk
Following is the search criteria...
Location : temple%cloud
Keywords : rural
Min. Price : 0
Max. Price : 170000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
#2
Scooby Regular
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Andy,
Can you email me a copy of the automater script and I'll have a look at it, hack it apart, swear at the machine, run it through script debugger, put it back together, and try and make it do what you want.
I can't promise miracles, but I'll give it a go.
Can you email me a copy of the automater script and I'll have a look at it, hack it apart, swear at the machine, run it through script debugger, put it back together, and try and make it do what you want.
I can't promise miracles, but I'll give it a go.
#4
Scooby Regular
Thread Starter
Join Date: Oct 2004
Location: Was Manc now Camden
Posts: 2,689
Likes: 0
Received 0 Likes
on
0 Posts
Cheers Markus, I just tried to reply but your mailbox is full, Mr Popular.
My email is andy@homeinfo.co.uk and if what you said in pm is true then you are an absolute hero!
Cheers
Andy
My email is andy@homeinfo.co.uk and if what you said in pm is true then you are an absolute hero!
Cheers
Andy
Trending Topics
#9
Scooby Regular
Thread Starter
Join Date: Oct 2004
Location: Was Manc now Camden
Posts: 2,689
Likes: 0
Received 0 Likes
on
0 Posts
Originally Posted by class_A
Scoobynet beats Ars then? I am poo at Applescript, but am curious as to the solution!
Thanks for the help Markus!
#10
Scooby Regular
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
punt it to terminal, lol, probably would have been something to do with using a perl script to achieve the same effect I did.
As for the solution, well, if you want a copy of the script, let me know. Essentially what I did was this:
* Ask Mail.app to give me the currently selected messages
* Create a repeat loop to repeat through the messages
* Ask mail for the "contents" ie; body of the message
* Use delimiters set to "new line" and search through the content of the current message one line at a time until I find a line that contains the word "Location" or "Keywords" as these are the lines that will contain the % character.
* When I find the two lines see if there is a % character by stepping, character by character through the line and seeing if it contains %, if it does, replace it with a space.
This is the slowest part of the script. If Applescript had a decent find and replace command then it would be much quicker (Acme script widgets does, and is great but costs )
* Whilst stepping through, I've been keeping the untouched lines, so I add the modified line(s), if they were modified, back into the block of data and then write it out to a file on the desktop
* repeat the above for all selected messages.
I would not consider myself an expert in AS but I do know a bit here and there.
My tips?
* Get Script Debugger, it's way, way better than Apple's Script Editor, or Xcode (unless you can line step debug scripts in xcode, not sure if you can, not tried for a while). Fully featured editor with debugging, I could not live without it
* Snoop around macscripter.net (think that's the place)
If you've any AS questions or need a script to do something, feel free to ask, I might be able to help out.
As for the solution, well, if you want a copy of the script, let me know. Essentially what I did was this:
* Ask Mail.app to give me the currently selected messages
* Create a repeat loop to repeat through the messages
* Ask mail for the "contents" ie; body of the message
* Use delimiters set to "new line" and search through the content of the current message one line at a time until I find a line that contains the word "Location" or "Keywords" as these are the lines that will contain the % character.
* When I find the two lines see if there is a % character by stepping, character by character through the line and seeing if it contains %, if it does, replace it with a space.
This is the slowest part of the script. If Applescript had a decent find and replace command then it would be much quicker (Acme script widgets does, and is great but costs )
* Whilst stepping through, I've been keeping the untouched lines, so I add the modified line(s), if they were modified, back into the block of data and then write it out to a file on the desktop
* repeat the above for all selected messages.
I would not consider myself an expert in AS but I do know a bit here and there.
My tips?
* Get Script Debugger, it's way, way better than Apple's Script Editor, or Xcode (unless you can line step debug scripts in xcode, not sure if you can, not tried for a while). Fully featured editor with debugging, I could not live without it
* Snoop around macscripter.net (think that's the place)
If you've any AS questions or need a script to do something, feel free to ask, I might be able to help out.
Thread
Thread Starter
Forum
Replies
Last Post