Archive for the ‘Mail’ Category

Fetch New Mail.app Messages from Your Phone

Thursday, March 13th, 2008

retrieve emailsThis post is intended for people with mobile phones that don’t have Internet access, but can receive emails in the form of text messages. You will also be interested in this post if you’ve had problems with Mail.app rules in Leopard.

Need to check for new messages in Mail.app from your stone-age mobile phone? No problem. Send yoursef an email with a preset subject like “MsgFetch” and your unread emails received that day will be forwarded to your phone. This way you don’t always forward to your phone, burning up all your text messages.

The script will append the sender name into the subject so it’s easy to glance at your phone and see who sent each message - since they’re all forwarded from your email address. The messages are marked as read in Mail.app so they won’t be resent if you issue another request later.

One more thing: This solution also gets around a problem with rules in Mail.app under Leopard. It seems that scripts called by a rule won’t generate a new mail message, which is something this script needs to do.

Instead of relying on the rules of Mail.app, the rule processing is baked into the Applescript. By setting the script to run on a periodic basis we can test for trigger emails in the inbox.

How do you get the script to run periodically? You can have iCal do it. Or you could use something like Lingon to configure launchd, which handles scheduled tasks in Leopard. This post has a screencast that covers Lingon.

You could also create a shell script that kicks off your Applescript, or a group of Applescripts for that matter. The shell script would look something like this:

osascript <path to script file>/ <script file>

or

osascript ~/Documents/scripts/mailforwarder.scpt

You can download the Applescript and read the in-line comments explaining how it works. But let’s take a quick look at two excerpts from the Applescript:

The first part of the script handles what a Mail.app rule would normally cover. Since rules aren’t working as expected the Applescript handles that duty by looking for an unread email with MsgFetch in the subject. If there is such a message the script calls a subroutine ( a chunk of script) called mail_forwarder.


The other part we’ll look at is located within the mail_forwarder subroutine. It finds the emails that arrived today. The next part, not shown here, checks to see if the message has been read.



The rest of the script has been covered in other Murphy Mac posts. It’s the part that creates and sends the mail message. Murphy’s posts on mailing files from Finder and retrieving files by email both create and send mail messages using Applescript. The Finder post has a screencast that goes with it.

Related posts:

Using Lingon

Creating a shell script

Other tricks with Mail: Pick a Playlist by Email - Retrieve a File by Email - Mail a File Dropped in a Finder Folder

Download Applescript

Retrieve a Remote File - by Email

Saturday, February 16th, 2008

zipIf you’re using an iPhone or a touch or some other mobile device this could be a very convenient way to retrieve a file from home and view it on your device.

Here’s the scenario: You’re on the bus, you realize your French homework is sitting at home on your Mac. Send yourself a text message with the path to the file. By the time you get to school and log on to a computer your file has been emailed. Problem solved.

Configure Murphy’s script to run every so often using something like launchd. Then send yourself an email. Include the path to the file you want sent in the body, like this:

/Users/murphy/Documents/PenskeFile.doc.

Mail will create a new message, attach the file, and send it to the address in the script. You can configure the script to run when a certain word is in the email subject, like FileGrab. This is an ideal use for rules in Mail.app. But rules don’t seem to work in Mail as of 10.5.1. Murphy hasn’t tried 10.5.2 yet.

Update:  If you leave the file name out the folder’s contents will be zipped and sent.

Instead of using rules, this script is written to run periodically. Maybe every ten minutes or so. If it sees an email with the keyword in the subject it checks for the file and sends it. If the file doesn’t exist the script sends an email that says so.

zip

Security hole? Well, Murphy doesn’t think so. The file will only be mailed to the address you specify in the script, it’s not a reply. (you could alter the script to have it reply, but that doesn’t seem like a good idea.) You can use secure email to send the request and the file. That’s secure.

Getting back to the mobile devices: Your unhacked iPhone and touch don’t let you download files. So you can’t SSH back to the house and grab the file. You could set up your Mac as a web server, but I wouldn’t want to do that.

Using this script the file is emailed to you, so you can view it in Mobile Mail or Gmail depending on what kind of file it is. You can easily view the file later, when you’re offline. The catch? You need to know the path to the file you’re retrieving. Don’t know the path? Here’s some help.

Windows Users: Have a look here.

Note: Script requires use of Mail.app. To schedule this script to run on a schedule you might want to try something like lingon for editing your launchd configuration.

Other Murphy scripts for working with Mail:

Sleep Your Mac by Email

Select a Playlist by Email

Get a List of Your Files by Email

Retrieve Mail.app Messages by Text Message (this post shows how to match emails with Applescript using multiple criteria)


Download Script

Select a Playlist by Email - And More

Sunday, February 3rd, 2008

Playlist by EmailI can see the comments now. “Why not just…” But let’s be patient and save judgements until you’ve read the whole post.

Yes, I know there are tons of ways to control iTunes from your iPhone or your touch or another computer or your fancy remote. (Murphy even dug up an old Pocket PC recently to try out Salling Clicker, which also supports BT phones) But there’s no harm in having yet another avenue for getting some music playing.

Murphy stumbled into a script that checks the content of an email for instructions on what to play in iTunes, like a playlist or an artist. But there’s more - just like the title of this post says. The script can also tell iTunes to play through external speakers via your Airport Express. That might not sound like much, but it is, because iTunes doesn’t provide the necessary hooks to control speaker selection. (more…)

Download Script

New and Improved: Finder Emailing

Thursday, June 28th, 2007

Murphy posted about emailing from Finder a while back. This new screencast was entered in the Macinstruct tutorial contest, winner to be announced next week.

Finder MailerJust drag a file to a folder and it flies off to a pre-determined email address. Optionally, have the action prompt you for a subject so you can find it later.

Murphy finds this technique extremely useful for quickly backing up important files to a dummy Gmail account - especially with the new 20MB attachment size. You have files you can’t bring yourself to delete? Drag them to the folder and they’re on their way to a mail server, just in case you want them later. No addressing, no need to click send. It’s just sent. Murphy knows you can drag files to the Mail icon in the Dock. This is more direct - no extra clicks!

If you’ve got multiple assistants you send files to all the time you could create a folder for each. Dragging a file to their folder is like dragging it to their inbox.

The new screencast details both a Folder Action and an Automator solution. They achieve the same thing in terms of sending. The difference is that the Automator method leaves the file in its original location on your disk, which might be more convenient. But the Folder Action method can be utilized from an SSH session. That opens up a lot of possibilities and offers extra convenience.

The Automator solution comes from a post on TUAW that was inspired by a post on MacOSXHints that was submitted by Murphy. How’s that for a chain of events?

Visit the previous post to download the AppleScripts used in the screencast.

Watch Now

Split Files Into Smaller Files

Thursday, May 3rd, 2007

split filesSometimes a file is just a little too big for the media you want to store it on or the pipe you want to squeeze it though. The split command is here to help. It’s fast, it’s easy - and it’s already on your Mac.

In the screencast Murphy splits a thirty-something megabyte video into 9mb chunks - so he can back them up on his gmail account. (I’m expecting a lot of “Wouldn’t it be easier to…” on this one.) Keep in mind this is not a video splitter. The pieces aren’t viewable until you reassemble them. But you can use split on all kinds of files, even your zip archives.

We’ll be using the cat command for reconstituting our original file. We’ve seen plenty of cat in previous screencasts, but we’ve never used it quite like this.

Also in the screencast: Murphy demonstrates that Folder Actions work in a Terminal session. He’ll copy the pieces from a split file to an action-enabled folder - and the pieces will be automatically mailed to his Gmail account! This post is action-packed.

Maybe you want to break up some super-jumbo files for dvd storage. Take a look at this if you’re planning on creating chunks over 2gb.

The syntax Murphy uses in the screencast for reassembly is the most straight-forward he saw anywhere on the web. If you look around a little you can probably find scripts that do the same thing. Or check out Murphy’s post on making a shell script, maybe you can make your own.


Watch Now