mac-os-x

recent posts related to the mac os x operating system

Two more Textmate commands (capitalize, CSV to list) alvin September 11, 2016 - 10:43am

As a “note to self,” I wrote two more Textmate commands yesterday, one to capitalize each word in a selection of words, and another to convert a CSV list of words to a simple list. Here’s the source code for the Capitalize command:

#!/bin/sh

perl -ne 'print ucfirst $_'

The $_ portion of that Perl command isn’t required, but I include it as a reminder to myself about how Textmate commands and snippets work.

Here’s the source code for my Textmate command that uses the Unix tr command to convert a CSV list of words (such as a paragraph of comma-separated words) into a simple list of words:

#!/bin/sh

tr , "\n"

As you can see, those commands are fairly simple. If you know Unix/Linux and then know a little about how to write Textmate commands, you can usually get it to do what you want. I like that you can use any Mac/Unix programming language or tool to solve the problem at hand.

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) alvin July 15, 2016 - 4:33pm

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?”