Murphy Mac » Posts in 'Advanced' category

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.

Share/Save/Bookmark

Script Download | Permalink

Video From iPhone Straight to Apple TV

rubeI 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 Email - Retrieve a File by Email - Mail a File Dropped in a Finder Folder

Share/Save/Bookmark

| Permalink

Random Filenames for Digital Photo Frame Images

RandomMany of the digital photo frames on the market still don’t have the ability to shuffle images and display them in random order.   A couple people I know have frames and want to mix up the photo stream a little. The first time I ran into this issue I used a Windows utility called renamer to assign random names to the image files. But what about a pure Mac solution?

There is one, and you don’t need anything other than OS X to get it done.  Skip to the screencast if you prefer - otherwise here’s what you do:

Place the files to be renamed in one folder. It’s best to have them all in one folder without subfolders. If you have images scattered inside subdirectories you’ll have to make some adjustments to these instructions.  USE A COPY OF YOUR ORIGINAL IMAGE FILES,  there’s no reason not to.

Open the Terminal from your Utilities folder in Applications. Type cd followed by a space. Then drag the folder containing the files from Finder to the Terminal window. Hit return. The Terminal prompt should update to indicate you’re now in the directory containing the images.  This folder should NOT BE THE SAME AS THE ONE YOUR ORIGINALS RESIDE IN.  Sorry for that, but it’s important.

Finally, type the following command in the Terminal:

for i in *.jpg; do mv $i $RANDOM.jpg; done

The command is case-sensitive.  If your images have names ending .JPG you’ll need to adjust the *.jpg part of the command above to use a capital JPG.

Hit return and your image files are renamed using random numbers.  Copy them to the digital photo frame and your images should cycle randomly.  Thanks to this thread at Mac Rumors Forums.

I’ve included a screencast for those not familiar with Terminal.  Be careful in the Terminal.  You can delete files accidentally and they won’t be in your Trash !  See this warning for more information.

Share/Save/Bookmark

Screencast | Permalink

Restore the Master Library Container in iTunes

LibraryRemember when iTunes used to have a Library container that you could select as the basis for a search of ALL your content? That was nice. Now if you want to search for a TV show in the library you need to click on the TV Shows node before initiating a search.

If there were a keyboard shortcut to select each container I’d use it, but I don’t see any such shortcuts. Thanks to the king of AppleScripts for iTunes I’ve pulled together some pieces that give me a solution.

Hidden Preferences If you really miss the all-inclusive Library container you can add it back into iTunes using an AppleScript application provided by Doug Adams called Change Hidden iTunes Preferences. From there you can script selection of that container or you can go a step further: I’m using TextExpander to kick off a script that facilitates iTunes searching. The script can select the Library container or go on to select a container like TV Shows, Movies, or Podcasts. The extra step is only required if you prefer to have search results limited by media type.

The commands to select the Library container were provided by Doug. When hooks for selecting other containers weren’t readily apparent (maybe they’re there and I didn’t see them) I moved on to another strategy: Selecting the Library and then scripting arrow key presses to move down the tree. So far that works ok. Last step: Place the cursor in the search box. Doug’s page on automating keystrokes helps there too.

scriptThe simple script, shown in the screenshot, can be kicked off with a keyboard shortcut. For me it means not using the mouse, and that’s worth the effort. Still, the script isn’t working 100% of the time. For example, if the Library node is already selected it fails. Needs a little work…

Share/Save/Bookmark

Murphy's Web Host | Permalink

Create an openssl Function

Remote Login With SSHThis is a quick way to make encrypting files using the terminal fast and convenient. Murphy posted instructions on making an interactive shell script to do essentially the same thing. This is a slightly different spin. Skip ahead to the screencast to see how easy file encryption can be. The openssl command we’re using is included with OS X.

Like other things we’ve covered - the specific example might not apply to you - but for people who’ve never used a function it might be helpful. Functions can make complicated Terminal commands more convenient to use.

To create the function just add this line to the .bash_profile file in your home directory:

des3() { openssl des3 -salt -in "$1" -out "$2"; }

Note that there’s a space after the opening curly bracket and a space before the closing curly bracket. All we need to remember is the function name, and to provide two file names: one to encrypt and one to be the output file.

The breakdown on the command: the first des3 is what we named the function. We can name it anything but des3 is what Murphy chose. The name of the function is what you’ll type whenever you use it.

The stuff in the curly brackets is what happens when we invoke the function. See this post for more on the openssl command.

The des3 following the openssl command is the type of encryption we’re using. It’s part of the openssl command syntax. We added $1 and $2 after the in and out respectively because they’re the two pieces of information we need when we invoke our function.

The $1 and $2 will be replaced with the paths we type into Terminal. In the screencast Murphy shows how to invoke the function. Instead of typing the paths he drags the file to be encrypted into the window - which saves us the typing. He also names the output file with a des3 extension to remind himself how he encrypted the input file.

As always, be careful with the Terminal if you’re not familiar with it. See Murphy’s warning about the dangerous possibilities.

Share/Save/Bookmark

Watch Screencast | Permalink