recent posts related to the mac os x operating system

How to set the Java version on Mac OS X (macOS) systems alvin July 20, 2016 - 8:11pm

I don’t remember where I first found this line of code, but if you put it in your Mac OS X ~/.bash_profile file, it’s an easy way to set your Mac Java version:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

I can confirm this works with the Bash shell on Mac OS X 10.10. When I run the java -version command after opening a new Mac Terminal window, the output is 1.8.0_25.

A slightly more difficult way to set your Mac Java version is to look under the /Library/Java/JavaVirtualMachines directory to see which versions are installed, and then manually set the version.

What is the Mac OS X (macOS) fonts folder? (to add new fonts)

Apple/Mac FAQ: I want to add new fonts to my Mac, what is the Mac OS X (macOS) fonts folder?

Just put any new font files in the Library/Fonts folder under your home directory. For instance, my Mac OS X username is alvin, so the correct fonts folder is:

Applescript: How to open a PDF in Preview and go directly to a page alvin July 7, 2016 - 7:43pm

I’m currently generating my new book on “functional programming in Scala” as a PDF using a combination of Pandoc and LaTeX, and as a result it feels like I’m opening the same PDF file about 100 times a day.

How to jump to a screen location using a mouse click with iTerm2?

When using iTerm2, if you’re editing a file with vim and want to jump to a specific location in the file using a mouse click, just hold down the [Option] key when you do a normal left mouse click. That will take you to the location directly under the mouse cursor. (Unless the mouse cursor is beyond the end of the line. In that case the text cursor will be moved to the end of that line.)

I mention vim here because I just learned about this when using vim, but you should be able to use this with any app when using iTerm2. This is an iTerm2 feature (not a vim feature).

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 alvin June 28, 2016 - 10:00am

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?

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.)