Murphy Mac - Screencasts and Tutorials » Posts in 'Mail' category

Auto Mail Redux Part II The Revenge

mailerA long long time ago Murphy showed you how to mail attachments with one click and drag of a file. No addressing, no clicking send.  Drag the file to a Finder folder and it was emailed to a pre-set address.  I used to use it for backing up files into a Gmail account.   You might find it useful for services like Evernote and Flickr as well.

Now we’ll show you how to do it in Automator, with enhancements.  First, the file name(s) of the attachments get added to your email’s subject line automatically.  Second, the sent files are placed in a Finder folder of sent items.  Murphy provided an Automator solution for this task before, but the email subject feature and the filing are new features.

Here’s a screencast that shows how it works.    When you want to send a file simply drag it to the folder and it’s sent.  No additional clicks.  You might create different versions of the Automator application.  For example, one might mail to a Flickr account and another might be used for sending a photo to four grandparents at once.

Feel free to suggest enhancements to the Automator workflow in the comments.  There’s a third party Automator action that can easily get file names without the full path name if that’s what you prefer.

You can see all the actions in the Automator workflow here.

Screencast | Permalink

iPhone Photo Rotation – Part Two

beautifulMurphy already posted about issues with mailing vertically-oriented photos from your ios4 iPhone:  Chances are your recipient sees the photo rotated 90 degrees to the left.  Web browsers – Safari included – don’t know how to read the exif orientation tag included with the jpg file.

My previous solution was to use an alternate camera app.  But I’ve got another approach that requires a Mac running Mail.

When I take a photo with my iPhone – in portrait orientation – I simply email it to myself.  My Mac is configured to watch for email with a particular subject and then automatically grab the attachment, strip the exif rotation information, and rotate the photo without using a tag.  Then my Mac mails the photo back to me.

Here’s the setup:

In Finder

In your home folder create a folder called lab with subfolders in and out.  Like this:

/Users/murphy/lab/in

/Users/murphy/lab/out

AppleScript

Download my AppleScript.  Edit the AppleScript and change all occurrences of ‘murphy” to the name of your home folder.  There are notes in the script to help you.

Automator

WorkflowCreate an Automator workflow.  You’ll need to add 4 actions in the same order they’re listed below.

  • Mail: New Mail Message
  • Finder: Get Specified Finder Items
  • Mail: Add Attachments to Front Message
  • Mail: Send Outgoing Messages

Only the first two Automator elements need further configuration.  The first one defines the address your altered photo will be emailed to.  You might add a subject as well.

Then specify this file path in the Finder element:

/Users/murphy/lab/out/outbound.jpg

Make sure you replace “murphy” with your home folder name.  The path points to the photo Automator will mail back to you. Save as a workflow. The AppleScript expects the workflow to be in a folder called _applescripts in your Documents folder. Edit the AppleScript if your workflow will be stored somewhere else.

Mail

WorkflowIn Mail you need a rule to kick off the AppleScript when a message arrives meeting certain criteria.  My rule looks like this screenshot.  The script runs when an email arrives with the subject “rotate”.  You might select a different word or phrase.  Make sure you set the script path to the location where you saved your AppleScript. More on Mail rules.

jhead

The AppleScript relies on a command line utility called jhead to strip the exif rotation tag, which I found in this TUAW post.  My script expects jhead to be in the /Users/murphy/lab/in folder.  After downloading jhead you’ll need to make it executable.  In the Terminal:

chmod +x path/to/jhead

In my case I entered chmod +x /Users/murphy/lab/in/jhead

That’s about it.  My script pulls the photo from the email, rotates it, strips the exif rotation information, copies it to another folder, and kicks off an Automator workflow to mail the photo back to me.

When I receive the altered photo on my iPhone I can simply forward it to someone.  If they view it in web Gmail they’ll see the photo inline-style within the email.  I prefer to save the photo to my camera roll and send it from there.  That way I’m prompted to select a size and recipients using web-based gmail get a thumbnail with a choice to view or download.

Notes

You might want to place jhead somewhere other than where I did.  If you move it you’ll need to edit the AppleScript.

Mail needs to be running on your Mac for this to work.

I used an Automator workflow to send the return email.  You can do it in AppleScript if you prefer, but I’ve had mixed results down that road.  Decided to try Automator.

You could use Automator to extract the attachment.  I’d already written a script to extract an attachment from Mail so it seemed like the way to go.

You could alter the AppleScript so everything happens in one folder.  I used two folders only to help me with troubleshooting the script the first time through.

Don’t forget to make jhead executable.

Dropbox Alternative

Here’s another alternate solution:  Dropbox

You could upload your images to Dropbox from your iPhone – then mark them as a favorite.  From there you copy the image to the clipboard to paste into a mail or save it down to your camera roll.   They won’t be full-size though.  And if you paste and mail it’ll be sent as a png.  But the orientation will be correct.  If you simply upload and send the link the orientation will be wrong.

OR

You could use something like my script above to place a full-size copy of your file in your Mac Dropbox.  Then you can access the photo from the Dropbox app on your iPhone.  You’ll still need to copy and paste or save it to the roll to get the rotation right.

perfect Yeah – it’s a lot to set up and you need a Mac running to use it. I can wake my Mac up from my phone so that’s not a big deal. And I find mail-based workarounds like this convenient to use. Still – maybe Apple should switch back to the old way until the browsers catch up.

Script Download | Permalink

Video From iPhone Straight to Apple TV

rubeNote: This was posted before Airplay. But it still applies to the old Apple TV.
I was thinking it would be nice to watch a video I’d just recorded with my iPhone on the Apple TV. But it’s kind of a pain to do that. I’d have to run the iPhone upstairs, plug it in, wait for it to sync, add the video to a playlist…

Alternative: I could upload the video to YouTube, but you have to fill out the fields to upload and it seems sometimes my Apple TV loses track of my YouTube account. Or at least loses access.

So I’ve got a Rube Goldberg alternative that makes it really simple from a user perspective – once you’ve done the upfront legwork. Just email the video to yourself, if it’s short enough. Let your Mac automatically grab the video from your email and drop it into iTunes.  My Apple TV seems to immediately sync on its own when new content is added to a Playlist that’s set to sync.

I’m using a pretty straightforward AppleScript and a rule configured in my Mac’s Mail program. Here’s what happens:

  • I email the video to myself with the subject atv.
  • The email arrives.
  • A Mail-based rule sees the subject and kicks off an AppleScript that copies the video file to the Automatically Add to iTunes folder in my iTunes Music folder.
  • The video gets added to my iTunes Library.
  • The video is added to a Smart Playlist.
  • The Apple TV is set to sync with the Smart Playlist.
  • The video is synced to my Apple TV.

That looks like a lot of stuff but the Mac will do all the work. There are only a couple things you need to set up:

  • Create a Smart Playlist and tell Apple TV to sync with it
  • Create a rule in mail and have it run the AppleScript when a matching email comes in.

Then all you do is email yourself the video. If you open Finder and look around in your iTunes Music folder you’ll see a folder called Automatically Add to iTunes. Anything that gets dropped in there gets added to your library, so that’s where the script copies the file.

I threw this script together quickly, there’s nothing fancy, no error checking – so feel free to post any enhancements.   My intention is to provide an example of what can be done easily with AppleScript and Mail rules.  It might help someone accomplish other tasks similar to this one.

Here’s a link to the script and screenshots of a Mail rule and sample Smart Playlist settings.   The script was saved as a text file.  You need to change the path in the third line of script to reflect your user name. You also need to save it as an AppleScript using AppleScript Editor.

In the Mail rule you need to change the path to where you saved your AppleScript.

Mail Rule Screenshot:
Mail_Rule

Smart Playlist Screenshot:
Mail_Rule

You might come up with something more sophisticated for the Smart Playlist…

Finally – here’s a look at the AppleScript, which you can download.

Mail_Rule

Other tricks with Mail: Pick a Playlist by EmailRetrieve a File by EmailMail a File Dropped in a Finder Folder

| Permalink

Fetch New Mail.app Messages from Your Phone

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 EmailRetrieve a File by EmailMail a File Dropped in a Finder Folder

Download Applescript | Permalink

Retrieve a Remote File – by Email

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 | Permalink