SQL: Sum Multiple Records in One Table

Something I cannot seem to memorize, how to sum multiple records in one table based on another field using SQL. For example:


Country    Visitors
-------------------
USA        140
Japan      50
USA        99
Japan      75

If you want to sum up the visitors based on country, then the following SQL-statement should do the trick:

select Country, sum(Visitors) as Visits from countries_combined_001 group by Country order by Visits desc;

Again, really obvious, in theory. ๐Ÿ˜‰

How to deal with Spaces in Filenames?

As an AppleScripter, you always have to deal with the creativity of your users regarding filenames. A simple fact of life. AppleScript is handing you the tools on a silver platter. So, let’s deal with it.

Read More »

Ringtones by NASA

I had my Whiskey-Tango-Foxtrott-Momentโ„ข today when I found this on NASA’s Website: Download NASA Sounds. The linked website contains directions how to use the provided sound bites as ringtones. Always wanted a geeky sounding ringtone? Here you go.

Now I have to figure out which one to use. ๐Ÿ˜‰

Download additional content for FCPX and Motion 5

The new Final Cut Pro X is available in the App Store as of now. Some of the complaints I read in the usual channels circled around the fact that the supplied templates for Final Cut Pro X and Motion 5 seem to be smaller in weight as usual. Do not despair young padwan, help is on the way. ๐Ÿ˜‰

If you follow this link, then you will find, and I quote: “Over 1300 sound effects” and “Additional presets for the Space Designer plug-in”, courtesy of Apple (about 640 MB to download).

If you are more of the Motion-type, then following this link allows you to access about 1.15 GB of Motion-goodness like Templates, Graphics, and sample media.

May the bandwith-cap-defyingโ„ข deity of your choice be with you. ๐Ÿ˜‰

Defining an asymmetric bleed in InDesign CS5.5 using AppleScript

Using AppleScript to efficiently create your documents in Adobe InDesign is a no-brainer for most of us. One could create template files to achieve the same result, but, should the need to change said templates arise, then it’s dialog hell. If you, dear reader, memorized the location of every possible document setting in the program by heart, then this post is not for you. I prefer to be able to see all settings by looking at a text, I therefore use AppleScripts to create the documents I’m working on. I already told you, I want to concentrate on the creative side of my work.

Read More »

Logging with launchd

Apple switched from cron to launchd a while ago, but the fact that launchd allows you to log the output of your program or script quite easily seems to be shrouded in mystery for no apparent reason. Do you know how to create/write logfiles using launchd-plists? If not, read on.

Read More »

Access Special Folders via AppleScript

There are certain folders which are not that easily accessible via AppleScript (or any other programming language for that matter) because the path to them has to be constructed by incorporating the (short) name of the current user account.

One of the most used constructs would be accessing the folder Documents located in the user’s $HOME, for example. The easiest way is the following string of commands:

set myDocumentFolder to path to documents folder as string

The result is the colon-delimited path as string, e.g. MacHD:Users:username:Documents:.

If you need the path to hand it over to a shell script or any other process requiring the Unix way of wording a path, use this approach:

set myDocumentFolder to POSIX path of (path to documents folder as string)

No surprise here, the answer will be something like this: /Users/username/Documents.

But what about accessing the user’s Library folder? If we continue like this:

set myUserLib to path to library folder as string

All we get is MacHD:Library:. Is there a way to tell AppleScript which Library folder we are really interested in? There sure is:

set myUserLib to path to library folder from user domain as string

Firing this command results in the path we are looking for: MacHD:Users:username:Library:. Telling AppleScript the domain we are interested in does the trick.

There are three domains at our disposal (there are actually some more, but those will be the subject of another post):

  • user
  • local
  • system

To cut a long story short, here are examples for the other two domains and the corresponding results:

  • set myLocalLib to path to library folder from local domain as string returns MacHD:Library:
  • set mySystemLib to path to library folder from system domain as string returns MacHD:System:Library:

It seems, that using from local domain is superfluous in regard of the folder Library, but good programming practice (and the resulting peace of mind) implies, that we should use the construct and be save from surprises later. ๐Ÿ˜‰

OS X: Go to (certain) Pref-Panes fast

Did you know that there is a shortcut to open certain panes in System Preferences in OS X?

If you want to open the Sound-Pane in System Preferences then try this key combination:

โ€“ any of the keycaps to modify the volume on your Mac

The same goes for the Monitors-Pane:

โ€“ keycap to increase or decrease monitor backlight

Just a quick tip for the impatient. ๐Ÿ˜‰ Works in 10.5.x and 10.6.x.

Diwali?

Today is the festival Diwali, translated “a row of lamps”. Just in case you need to know.

Get the whole story on Wikipedia or from the BBC.

Tip: Launching Dashboard via AppleScript

Just a short tip: Your Dashboard in OS X contains up to the minute information about things that are of interest to you, right? I use a script to launch iTunes and Mail in the morning while making coffee, the other thing I launch every morning is the Dashboard to get an overview of things I want to know, e.g. weather-reports, stocks and the like.

It seems that it is not that widely known, that you are able to launch Dashboard via AppleScript, as well. If you got an error message like ‘Dashboard got an error: Application isnโ€™t running.’ while using activate, launch does the trick. It is as simple as that:


tell application "Dashboard"
	launch
end tell

Bonus: If you are administering one or more OS X servers, then check your available Widgets in Dashboard, there is one to give you information about the vitals of your server(s).