Convert AVI files for AppleTV

Once you’ve setup Home Sharing so you can play movies from iTunes on the AppleTV, you’ll notice that some movie types won’t play.

Handbrake is a free tool that can convert avi and other video type to mp4 movies that will play on the AppleTV.  But conversion of more than a few is tedious using the app.

It turns out there is a HandBrake CLI tool you can  download for doing batch conversions.

Change into the directory of files you want to convert. (It is okay if there are subdirectories you also want to process.)

cd /Volumes/Data/Movies

Here is the command I am using for the conversion*:

find . -type file
  -exec \
  /Volumes/HandBrake-0.10.5-MacOSX.6_CLI_x86_64/HandBrakeCLI \
  -i "{}" \
  -o "{}-AppleTV.mp4" \
  --preset="AppleTV" \;

That command will find all files and attempt to convert them using the ‘AppleTV’ preset.

It will output them in the same directory as the original with the suffix “-AppleTV.mp4”.

Of course if you only want to handle certain file types you can change or add to the options to the find command  (-name “*.avi” for example).

To clean up the original files after you are happy with the converted files:

IFS=$'\n';for orig in $(find . -name "*-AppleTV.mp4" | sed -e 's/-AppleTV.mp4//g'); do rm -i ${orig}; done

And finally you can rename the new converted files to remove the old file extension and “-AppleTV”:

IFS=$'\n';for new in $(find . -name "*-AppleTV.mp4"); do mv -i "$new" "$(echo $new | sed 's/\....-AppleTV.mp4/.mp4/g')"; done

*Use your own path to the HandBrakeCLI. I just dragged it into Terminal from the downloaded dmg.

dockutil 2.0.0 is out

It has been a long time coming, but I finally made time to attempt to get dockutil working better with cfprefsd.

I decided to use defaults rather than PyObjC.  Although in hindsight it probably doesn’t matter.  They both have quirks when running as root.

But defaults actually does handle paths correctly, and dockutil has always used paths to the dock plist, so that fits well.

At some point we will likely need to change dockutil to take users or domains rather than paths so it works better with CFPreferences.

But for now we can stay with paths to preserve compatibility with existing scripts using dockutil.

I expect some bugs, so please test and report them on github.

Launchd Tools Released

Launchd Tools are for reading and creating launchd jobs.

For example, to see info about all Apple LaunchAgents and LaunchDaemons.

launchd2cmd /System/Library/Launch*/*

Or to create your own launchd job from an existing command:

cmd2launchd /usr/local/bin/daemond -d --mode foreground

Check it out here: https://github.com/kcrawford/launchd_tools

10.9 Mavericks is your security update for 10.6 through 10.8.5

Mavericks is free.

Its system requirements are the same as for Mountain Lion

http://www.apple.com/osx/specs/

http://support.apple.com/kb/HT5444

It is also a security update:

http://support.apple.com/kb/HT1222

http://support.apple.com/kb/HT6011

I surmise that Apple does not intend to provide security updates for older OS versions.  At least not for 10.8.

If you want to get patched, start upgrading to 10.9…

Update: 10/4/2013

While it was fun to speculate about Apple forcing us to upgrade to 10.9.  It was just speculation.  I now believe I was wrong and I expect Apple to release updates for older versions similar to its past behavior.

 

Cursor Tracking Lag Caused by system_profiler

We’ve noticed problems with mouse cursor tracking, on Thunderbolt Macs attached to displays.

In the middle of moving the cursor with mouse or trackpad, the cursor jumps or skips making it difficult to control.

We tracked down the problem to background runs of system_profiler.  Specifically, when system_profiler queries the display for information.

Running system_profiler without flags or with the SPDisplaysDataType data type triggers the problem.

To reproduce the problem at its worst, run the following in Terminal on a Thunderbolt Mac attached to a display and attempt to use the tracking device:

while [ 1 ]; do system_profiler SPDisplaysDataType; done

Apple is aware of the issue, but has stated that this is expected behavior.

Many tools that rely on system_profiler trigger the issue including JAMF Casper Suite, Puppet, and Apple Remote Desktop.  These and other tools routinely inventory the Mac using system_profiler.

There is currently no workaround for getting display information such as Display serial number.  And the only way to avoid the trigger is to run system profiler with each data type excluding SPDisplaysDataType.

If you think Apple should address the issue, please let them know.

Tips for writing command line tools in ruby

  1. Option parsing: Read this article by Allen Wei on RubyLearning Blog for a great overview.  I recommend sticking with the built-in OptionParser if you want to reduce dependencies.
  2. If you want your code to be loadable so you can access functions and classes in the irb console for testing, use the following pattern:
    def main
     #option parsing and execution code here
    end
    if __FILE__ == $0
     main()
    end

    This way the main function will only be automatically called if the script is being executed on the command line.
    And in irb, you can call your functions and classes as you see fit for testing without triggering your whole script to run.

    Note that this is similar to the python __main__ test if you are coming from a python background.

  3. Naming without ruby’s.rb extension: You can name your executable without the rb extension if you wish, just be sure to include your shebang (#!)

    To use the user’s default ruby, use:
    #!/usr/bin/env ruby
    But in some cases you may want the specify the path to ruby so you can use macruby or rubycocoa if you are need those frameworks to be available
    #!/usr/bin/ruby

    When testing in irb,
    require 'script-name'
    won’t work without the rb extension, but
    load 'script-name'
    does work.
  4. Use exit codes. When your script fails or needs to communicate status at exit, use standard exit status codes.
    Exit zero for default success status
    exit 0
    Exit any other number for a failure or warning status. You choose the exit codes for your tool, but be sure to document them if they require more explanation than simple success or failure.
    exit 27
  5. Output to stderr using:
    $stderr.puts "error: problem ...."

Bootable Software RAID 0+1, 1+0 in Mac OS X

Software RAID striped mirrors or mirrored stripes are possible in Mac OS X. They may be 10.5 only. I haven’t tested other versions.

Simply create your striped sets using DiskUtility or diskutil, then use the command line diskutil and supply the /dev/diskx entries of the stripe sets when creating your mirror.

First run diskutil list to get the /dev/disk entries for each stripe, then create your mirror using:

diskutil createRAID mirror MirrorName JHFS+ disk1 disk2

where disk1 is the device for the first stripe set and disk2 is the device for the second stripe set.

The result is also bootable and will display correctly as a nested RAID in DiskUtility.app.