Murphy Mac - Screencasts and Tutorials » Posts in 'Mac OS X' category

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.

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…

Murphy's Web Host | Permalink

Reboot or Sleep a Mac from your iPhone

Sometimes Murphy is just a little too lazy to go upstairs and reboot a Mac that needs rebooting. With an iPhone or iPod touch you don’t need to leave the sofa.

Today, Murphy was watching tv on the iPhone via EyeTV’s iPhone app. It started to lock up so a reboot seemed like a good idea. Murphy has Touch Term installed on the iPhone. And the Mac is set to accept SSH sessions. One tap to connect and one command to start the reboot was all it took. Here’s what you need:

  • First, go to Sharing in your System Preferences. Turn on Remote Login. This allows your Mac to allow incoming SSH sessions.
  • On your iPhone install Touch Term, or some other SSH client. Murphy remembers getting Touch Term for free, but now it starts at $3.99. You might want to comparison shop for similar products.
  • Next, configure Touch Term to connect to your Mac, either by name or ip address.
  • Once you’ve connected just type the command to reboot your Mac, and press Return. Here’s the command:    sudo shutdown -r now

Murphy took the extra step of creating a shell script to run that command, so there’s less to type when it’s time to reboot.  That’s all there is to it.

You might want a command to send your Mac to sleep instead of rebooting it.  This command should accomplish that:   osascript -e 'tell application "System Events" to sleep'

Of course, you can always try something completely different.  A long time ago Murphy wrote some posts about using the Mail app on a Mac to trigger events.  Murphy has Applescripts on the Mac that do different things when emails come in with certain characteristics.  Scripts that adjust iTunes, retrieve files, or put the Mac to sleep.  The whole thing was based on a post here.

Some of these scripts had issues with different updates to OS X and changes to Mail.  Your results may vary…

I haven’t looked into other ways to reboot my Mac from the iPhone, so if you’ve got a good way let me know.

As always, be careful when using the Terminal.

| Permalink

Direct Access to Screen Sharing

Screen SharingMurphy has a new favorite Snippet for TextExpander. Direct access to a Screen Sharing session with a couple of key strokes, from anywhere. Let’s back up and see Murphy’s awkward way first.

The Screen Sharing application is arguably tucked away, it’s not sitting in your Applications folder. Don’t know why. But you can select a computer on your network in the Finder and then click Screen Sharing to launch a session. For Murphy, this usually involved some keystrokes to bring a Finder window up front and then some mouse movement. Too much energy.

Now, wherever Murphy is within OS X, he can type a few characters on his keyboard, like ssz.   He doesn’t need to be in Finder, he doesn’t need to open Spotlight, he doesn’t need to poke around with the mouse. A window opens instantly with the Screen Sharing session live and ready to go.  It even works while running a full-screen Fusion session.

If you aren’t familiar with TextExpander ($29.95) take a look at Murphy’s introduction. The utility allows you to create “Snippets” – a series of keyboard characters that trigger different results. Snippets can replace “mmz” with the text “Murphy Mac” wherever you’re entering text. Or they can run a shell script or Applescript. In Murphy’s Screen Sharing example a brief Applescript runs to launch the session whenever “ssz” is entered. The key combination is up to you, but it’s probably best to come up with a system – and to not use words you’re likely to type just for the sake of typing them.

Here’s what the Applescript looks like. Not much to say about that. Change the ip address to the ip of the machine you want to control. That’s it. We’ll assume you’ve activated Screen Sharing on the remote machine.


What about the entry you need to make in TextExpander? That’s pretty easy too.
Here’s Murphy’s TextExpander entry. Very simple: The type of entry is AppleScript. Then the AppleScript itself. And finally the text string you want to type to kick off the script. TextExpander

Murphy posted a while back about opening web pages directly with TextExpander. Here are a couple other related posts:

Launch applications from Terminal
Launch applications from Spotlight

TextExpander - Free Trial | 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.

Watch Screencast | Permalink