mac-os-x

recent posts related to the mac os x operating system

How to insert text with a custom TextMate Bundle snippet

As a quick note to self, I just created a TextMate Bundle snippet to insert some text at the current cursor position. Using TextMate 2.0.x, I did it with the following steps. I’ll go through these steps quickly as I’m just writing this for myself:

Simple iTunes AppleScript script examples

If you’ve never used AppleScript, here are two iTunes AppleScript examples to get you going. First, This one tells iTunes to play the playlist named “My Favorites”:

tell application "iTunes"
    play playlist "My Favorites"
end tell

That script starts playing a random song from that playlist. If you want to start by playing the first song of that playlist, this script will do the trick:

Apple Magic Mouse 2 - How long to charge the battery? alvin April 6, 2016 - 10:42pm

I recently bought a new iMac, and it came with a “Magic Mouse 2,” which is like the original Magic Mouse, but this one has a built-in battery. (It would have been nice if the documentation mentioned that, but that’s another story.) Once I figured out that you could charge it, I quickly wondered, “How long do you need to charge the Magic Mouse 2?”

A Mac iTunes backup script (How I backup my iTunes music using find and tar)

Here’s a little one-liner I use to backup my iTunes music on my Mac OS X systems:

find . -name '*.mp3' -type f -mtime -365 -print0 | xargs -0 tar rvf ~/iTunesBackup.20150118.tar

The way this works is that I move into the Music folder on my OS X system, then run that command, and it creates the tar file shown at the end of the command. This command copies all *.mp3 files that are under the Music folder that have been modified in the last 365 days into the resulting tar file. If you have files other than MP3 files that you want to back up, or if you want to change the date range of the backup file created, just change (or remove) those options in the find command. Note that the -print0 option is needed to back up filenames and directories that contain blank spaces. (See my Unix/Linux find command examples for many more find command examples.)

Mac OS X FAQ: Where can I find the iLife sound effects?

Apple Mac OS X FAQ: Where can I find the iLife sound effects?

As of Mac OS X 10.10, the iLife sound effects are under this directory:

/Library/Audio/Apple Loops/Apple/iLife Sound Effects/

Under that directory you’ll find folders named Ambience, Animals, Booms, Foley, Jingles, Stingers, and many more. The sound effects/clips are under those folders.

How to size (or resize) application windows in AppleScript

AppleScript FAQ: How can I size or resize an application window using AppleScript?

To resize an application window with AppleScript, use a command like this:

tell application "Safari"
    set bounds of front window to {300, 30, 1200, 900}
end tell

That command tells the Safari browser to have the following size and location properties:

How to run a multiline AppleScript script from a Unix shell script (osascript)

This little example shows the syntax of how to run some AppleScript/osascript from a Unix shell script on a Mac OS X system:

#!/bin/sh

osascript <<EOF
tell application "Safari"
  close window 1
end tell
EOF

Just put your AppleScript in between the EOF parts, save it to a file, make the file executable, and this gives you a nice way to run a multiline AppleScript script from a shell script.

Here’s another example of what this looks like:

How to close a Mac OS X app from a shell script (or command line)

If you ever need to close a Mac OS X application (gracefully) from the Mac Terminal command line or from a shell script, I can confirm that this command works:

osascript -e 'quit app "Safari"'

I use that command from a Mac/Unix shell script to close the Safari browser in an automation script I’m writing, and it works fine. Just replace Safari in that command with the name of the application you want to close.