Read Mac Hacks Online

Authors: Chris Seibold

Tags: #COMPUTERS / Operating Systems / Macintosh

Mac Hacks (16 page)

Hack 21
. Turn Your Desktop into a Fount of Useful Info

The
desktop is generally reserved for displaying beautiful
Apple-supplied images or pictures from your iPhoto library. This hack
explains how to display
useful
information on your
desktop with GeekTool.

Your desktop is slacking. While your other applications are off
collecting pertinent information and displaying interesting results (even
your screensaver can display RSS feeds) the desktop just sits there,
rarely changing and providing no input into your daily computing
life.

What would be great would be a way to have your desktop display
something useful and timely. This concept harkens back to one of the
earliest OS X hacks: running a movie as your desktop background. While
interesting, those who actually ran movies on their desktops quickly found
that not only was the hack processor intensive, it was also very
distracting. With this lesson in mind, it is obvious that choosing which
information the desktop displays is almost as important as getting the
desktop to tell you a little something about what’s going on in the world.
The ideal type of information for desktop residence would be something
that’s updated relatively infrequently, isn’t of crucial importance (since
you won’t see it if you have a bunch of windows open), and can impart a
vast amount of info at glance.

What
fits all the above criteria? Traffic! A quick glance at the
route(s) you take to and from work will tell you volumes about what you’re
likely to face on the commute. You can’t personally
do
anything to speed up the traffic flow, but you can
change your travel plan if one path looks intractably tangled.

First, it’s a good idea to find a traffic cam that displays the area
you’re interested in. In this example, I-62 at Lovell Road is potential
trouble spot for those traveling east or west around the Knoxville area. A
quick Google search reveals that there is indeed a traffic cam devoted to
that particular spot (no surprise there). For those playing along at home,
here’s
the
URL
.

Once you confirm that the traffic cam is available, it’s time to go
about getting said image onto the desktop. There are a variety ways to do
this, but installing one piece of free software not only makes the process
simpler, it also makes it much more adaptable as your cravings for an
information-packed desktop grow. Head to the Mac App Store and download
GeekTool, an app that lets you make tiny apps for your desktop. These tiny
apps are called
geeklets
and can offer a lot of
functionality. The ease of getting GeekTool from the App Store is nice,
and the price (free) is even better. Once the blue bar disappears from
Launchpad, launch GeekTool (
Figure 4-9
).

Figure 4-9. It might look a little intimidating, but GeekTool will make your
desktop better.

We’ve got a video feed we want on the desktop, so let’s start by
dragging GeekTool’s Image icon to your desktop. The result is shown in
Figure 4-10
.

Figure 4-10. Wow, that looks pretty darn complicated! Don’t be put off by the
appearance—images in GeekTool are actually very easy to use.

The first thing we need to do is add the URL to GeekTool so it knows
where to get the image. Recall that we found a traffic cam earlier, but
GeekTool can’t pull the image directly from that page. GeekTool wants
something that’s an image, so in your web browser, right-click the traffic
cam feed you want and then select “Open Image in New Tab” (
Figure 4-11
). Then, in the new tab,
copy that URL and you’re almost done.

This image is updated every few seconds, so it’s a great way to
learn about the traffic at any particular moment, but we need to get
GeekTool to display it. That’s easy: back in the GeekTool Properties box
(shown on the right in
Figure 4-10
), paste the URL into
the aptly named URL box and then hit Return. If the URL is valid, your
image will show up in the box (
Figure 4-12
). To make sure the
image updates, in the Properties box, enter a number in the “Refresh every
__s” box, like
10
if you want a new image every ten
seconds.

At this point you’re technically done but there are a few tweaks you
can make. You can resize the pic by dragging the double-arrow handle in
its lower-right corner; use the slider in the Properties box to set its
opacity; and drag the image to wherever you want it displayed. You can
also tell GeekTool whether you want traffic on top of your other apps or
lingering in the background using the “Keep on Top” checkbox in the
Properties box.

Figure 4-11. Grabbing the URL of the traffic cam.
Figure 4-12. Wow, you’ve got traffic on your desktop. You should start giving
updates to your coworkers and calling yourself the Eye in the
Sky.

That’s
a pretty nifty trick, but GeekTool isn’t a one-trick pony.
If you want more GeekTool goodness, visit
Brett Terpstra’s
site
, or
http://www.macosxtips.co.uk/geeklets
. Remember: you can
edit the scripts that others use in their geeklets, so the world is soon
to be on your
desktop.

Chapter 5
. Make It Automatic

In the olden days, computers promised shorter workweeks and more
leisure time (or, as some call free time, naps). It hasn’t quite worked out
that way. Accountants don’t get to use all the time they save from not
having to do computations for naps—they just get to use that time for other
accounting tasks. That doesn’t mean a computer can’t save you time or that
you should give up the dream. Computers are great at doing things without
your supervision, you just have to tell them what to do. This chapter
explains some ways to automate mundane tasks.

Hack 22
. Getting Things Done with AppleScript

Everyone
wants a clean desktop, but no one wants to perform all the
dragging and dropping required to achieve a tidy computing environment.
Forget the carpal tunnel–inducing drag-and-drop method: let AppleScript do
the work.

Everyone uses their Mac a little differently. Some people are
conscientious and put all their documents in the Documents folder, all
their pics in the Pictures folder, and all their movies in the Movies
folder. Some people don’t work that way: they use the desktop just like
you’d use a real desktop—as a temporary storage place for whatever you
happen to be working on at the time. Still other users use the desktop as
a repository for every file they run across during a particular computing
session. They don’t bother putting anything away until the desktop is
cluttered beyond hope.

The old excuse for having a cluttered desktop is that it was the
easiest place to find a file. Sure, it looked messy and each one of those
icons was actually a little performance-sapping window, but you didn’t
have to open your Documents folder and hope you put that TextEdit file in
there instead of in the Pictures folder or something. At least that was
the argument.

With
the integration of iCloud and the Finder’s slick built-in
All My Files option, it’s actually a lot faster to properly place files
and use All My Files then to make your desktop a digital catchall. But
die-hard clutterers toss stuff on the desktop out of habit. They need
serious help—the kind of help only an app can provide. As it turns out,
the files on the desktop are likely of predictable types, and so they’re
easily categorized, which means the process of cleaning up the desktop
could be easily automated.

You can’t say “automation” without thinking of Automator when you’re
using a Mac, and Automator holds the key to a clean desktop. What would be
ideal is an AppleScript that will put everything in the appropriate
folder: MP3s in the Music folder, documents in the Documents folder,
movies in the Movies folder, etc. Turns out, this is relatively easy to
do.

Note: The following script will fail if a file exists in the
destination with the same name as the file being moved. Think of it as a
safety precaution so that important data doesn’t get overwritten.

Creating the Script

To
get started on your AppleScript, launch the AppleScript
Editor (Applications→Utilities→AppleScript Editor). Here’s the script
that will identify files on your desktop by their extension and then
move them to the appropriate folders. Here’s the script we’ll be using
for this hack (you can either type it in or download it from this book’s
catalog page
):

Note: In the following script, change every instance of
username
to your actual username (unless
your username happens to
be
username). Your
username is the same as the name that graces your Home folder.

tell
application
"Finder"
set
theDesktop
to
alias
"
:
Users
:
username
:
Desktop
:
"
--Where to put stuff
set theMusic to alias "
:
Users
:
username
:
Music
:
"
set thePics to alias "
:
Users
:
username
:
Pictures
:
"
set theVideos to alias "
:
Users
:
username
:
Movies
:
"
set theDocs to alias "
:
Users
:
username
:
Documents
:
"
--filetype by extension
set musicExt to {"
.
mp3
", "
.
aac
"}
set picsExt to {"
.
jpg
", "
.
gif
", "
.
tif
", "
.
tiff
", "
.
png
"}
set videosExt to {"
.
avi
", "
.
mpg
", "
.
mov
", "
.
mp4
"}
set docsExt to {"
.
rtf
", "
.
txt
", "
.
doc
"
}
set
allFiles
to
files
of
theDesktop
repeat
with
theFile
in
allFiles
copy
name
of
theFile
as
string
to
FileName
repeat
with
ext
in
musicExt
if
FileName
ends with
ext
then
move
theFile
to
theMusic
end
if
end
repeat
repeat
with
ext
in
picsExt
if
FileName
ends with
ext
then
move
theFile
to
thePics
end
if
end
repeat
repeat
with
ext
in
docsExt
if
FileName
ends with
ext
then
move
theFile
to
theDocs
end
if
end
repeat
repeat
with
ext
in
videosExt
if
FileName
ends with
ext
then
move
theFile
to
theVideos
end
if
end
repeat
end
repeat
end
tell

Warning: This script works recursively, meaning that any folders
(but not drives) on your desktop will be sorted along with any files.
So it’s a good idea to use this script only if your desktop is
cluttered with files, not folders.

A closer look at what’s going on here is in order because you’ll
likely want to modify the script to suit your needs. The following bit
of the script invokes the Finder and tells it to look at the
desktop:

tell
application
"Finder"
set
theDesktop
to
alias
"
:
Users
:
username
:
Desktop
:
"

Here, the desktop is being defined by the path
:Users:
username
:Desktop:
.
You could change this path to tell the Finder to examine and clean up a
different folder. If you wanted to run this script on your Downloads
folder, for example, change it to
:Users:
username
:Downloads:.
Note the colons—in AppleScript, colons replace the more familiar slash
(/) that’s used when working in Terminal.

The next section of the script defines where the files are going
to end up:

--Where to put stuff
set
theMusic
to
alias
"
:
Users
:
username
:
Music
:
"
set thePics to alias "
:
Users
:
username
:
Pictures
:
"
set theVideos to alias "
:
Users
:
username
:
Movies
:
"
set theDocs to alias "
:
Users
:
username
:
Documents
:
"
Good Comments Are Good Code

In
AppleScript Editor, typing -- indicates a comment; in
other words, typing two hyphens tells the editor to ignore whatever
follows. While the computer doesn’t need the info in comments to
figure out what to do,
you’ll
need the comments
to remember what you did.

You can adapt the script to folders of your choice by changing the
paths to different folders. If you wanted your music to end up in a
folder called NewMusic within your Music folder, say, you’d tell the
script to burrow one level deeper in the folder by adding one more level
to the path:
:Users:
username
:Music:NewMusic:
.

The next section of the script defines which extension belongs to
which kind of file:

--filetype by extension
set
musicExt
to
{
".mp3"
,
".aac"
}
set
picsExt
to
{
".jpg"
,
".gif"
,
".tif"
,
".tiff"
,
".png"
}
set
videosExt
to
{
".avi"
,
".mpg"
,
".mov"
,
".mp4"
}
set
docsExt
to
{
".rtf"
,
".txt"
,
".doc"
}

If these extensions aren’t sufficient, you can add your own. For
example, if you want to include Photoshop files among the files sorted
as pictures, you’d simply add
".psd"
inside the brackets on the
set
picsExt
line.

If you type the script into AppleScript Editor window, you’ll end
up with a rather bland-looking script as shown
in
Figure 5-1
.

Figure 5-1. After you spend a little time with AppleScripts, you’ll be able
to tell immediately that this file hasn’t been compiled yet.
You Don’t Have to Type in AppleScript Editor

AppleScript Editor
is great for
editing
AppleScripts,
but it isn’t great for
writing
them. Nothing
against AppleScript Editor—it just lacks a lot of the tools that
coders like to use. So if you have a text-editing program you’d rather
use, like TextMate or some other application, feel free to write the
script in your preferred editor and then paste or import the code into
AppleScript Editor.

You
probably already know this isn’t right: scripts are
supposed to be color-coded and indented. No problem—simply click the
Compile button (it looks like a hammer), AppleScript Editor will work a
little magic, and everything will look as expected (
Figure 5-2
). As a bonus,
AppleScript Editor will find any structural errors (unclosed quotation
marks, for example) and alert you.

Figure 5-2. AppleScript Editor took that boring wall of text and styled,
indented, and colorized the code, making it look like everything was
intentional. Amazing!

If
you’re only going to need this script very occasionally,
you could just save it as a script. Then, whenever you want to clean up
your desktop, fire up AppleScript Editor and hit the big green Run
button. That’s a great option for the occasionally untidy, but for
desktop abusers it isn’t the best idea; those folks need to run the
script on a daily basis, and could use a way to run the script with a
minimal amount of hassle. If you’re in that category, save the script as
an application, using the File Format pop-up menu (
Figure 5-3
). (If you’re using
Mountain Lion, you have to press the Option key to make the Save As item
appear in the File menu.)

Figure 5-3. You’re creating an application—won’t Mom be proud? Maybe not,
but your desktop will be clean with just a few clicks.

Other books

Back To Me by Unknown
Magic Can Be Murder by Vivian Vande Velde
The Lover by Robin Schone
Deadlock (Ryan Lock 2) by Black, Sean
The Boy on the Porch by Sharon Creech
Innocent by Eric Walters


readsbookonline.com Copyright 2016 - 2024