New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

Looking for AppleScript help

Post Reply New Thread Subscribe

Thread Tools
Posts: n/a


I'm a Newbie to Mac-Forums and to AppleScript. I can't seem to find any forums dedicated AppleScript so I will post this here as a start.

While I have used a Mac at home for many years my recent programing has been in M$ VBA on my employers PC. Looking at AppleScript I can see some potential but the script editor is not as powerful the VBA editor when it comes to learning the language. I learn best by studying sample scripts but I have been unable to find a script that does anything like what I want to do.

I am trying to export a large number of e-mails from OS X Mail and save them as simple text files. I am struggling to both understand the object structure and how to reference it. Therefore the information in the Dictionary doesn't help me much.

The generic algorithm steps would go something like:
For every message in the inbox
if the message subject is like "ABC Corp" then
Save message as plain text "subject.txt" in "xyz" directory
move message to trash
end if
next message

Can anyone offer some support?


QUOTE Thanks

witeshark's Avatar
Member Since: Mar 09, 2004
Location: Miami FL
Posts: 2,860
witeshark will become famous soon enough
Mac Specs: G4 1Ghz OS X 10.4.7

witeshark is offline
Here is an example from the Applescript applications:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
set theText to "This AppleScript is intended to be used as an AppleScript rule action, but is also an example of how to write scripts that act on a selection of messages or mailboxes." & return & return & "To view this script, hold down the option key and select it again from the Scripts menu."
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
-- If this is not being executed as a rule action,
-- getting the name of theRule variable will fail.
set theRuleName to name of theRule
set theText to "The rule named '" & theRuleName & "' matched this message:"
set theText to theText & return & return & "Subject: " & theSubject
display dialog theText
set theText to ""
end try
end repeat
if theText is not equal to "" then
display dialog theText buttons {"OK"} default button 1
end if
end tell
end perform mail action with messages
end using terms from
You may well be able to use this one with some modifications
QUOTE Thanks
Posts: n/a

Originally Posted by witeshark
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
Thanks for the reply! I copied into the script editor and had to remove the first and last two lines for the syntax check to work :confused: however that brought me back to th problem i have been having looping through each message. "theMessages" is undefined. Yesterday I tried seting theMessages something like:

tell application "Mail"
set everyMessage to every message
repeat with eachMessage in everyMessage
set theSubject to subject of eachMessage
(*code identify and so save messages*)
end repeat
end tell

and I would get, NSCannontCreateScriptCommandError on "every Message"

How do I get a set of messages, specifically the ones in the Inbox, so I can loop through them?

Your help is appreciated.


QUOTE Thanks

Post Reply New Thread Subscribe

« Login panel customization | firewire HD »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 04:20 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?