Rocu.de

Love, caffeine and omlette

Tag: mac os x

Manage your Mac Apps with homebrew-cask

A while ago I became interested in automating the setup of my Macs. I started my journey with chef-solo, however this wasn't really practical for me, so I switched to homesick to manage my dotfiles.

Unfortunately that left me without a solution to install my apps automatically.

Not any more. homebrew-cask to the rescue!

Take a walk

Image Source: Flickr/megoizzy (CC BY-SA 2.0)

What is homebrew-cask

homebrew-cask is a Homebrew extension that allows you to install your apps like this:

brew cask install evernote

How to install homebrew-cask

If you already use homebrew, installing homebrew-cask is really simple:

brew tap phinze/homebrew-cask
brew install brew-cask

If you have Alfred installed you should also configure it, so that it recognizes apps managed by homebrew-cask.

brew cask alfred link

Using homebrew-cask

Using homebrew-cask is simple. You install apps using the brew cask install command. Evernote for example, you would install like this:

brew cask install evernote

Create a little script to install your Apps

I store all my apps in a file called ~/.brew. In order to install the apps I just have to run it.

This is how you create your own:

touch ~/.brew
chmod +x ~/.brew

Now fill it with the Apps you want to install across all your Mac's.

For me this looks like:

#!/bin/bash
brew cask install google-chrome  
…
brew cask install rubymine  
brew cask install charles  
brew cask install mou  
brew cask install bit-torrent-sync  

I have this file on GitHub and symlink it with homesick. When I am on a new Mac I just have to run

~/.brew

That installs all my common apps.

Create own casks

There are over 300 casks available already. You can view a list with

brew cask search

If your favorite app is missing it is really simple to add it.

In the example below I create a Cask for Soulver.

brew cask create soulver

An editor opens with the newly generated cask.

class Soulver < Cask  
   url ''
   homepage ''
   version ''
   sha1 ''
   link ''
end  

You just have to fill in the download URL of the app, the apps name, the version, the sha1 checksum of the download and it's homepage.

class Soulver < Cask  
  url 'http://www.acqualia.com/files/download.php?product=soulver'
  homepage 'http://www.acqualia.com/soulver/'
  version 'latest'
  no_checksum
  link 'Soulver.app'
end  

In Soulver's case the download URL does always refer to the latest version. So in this case I used no_checksum, so that this Cask will not break in the future.

Now audit your cask:

$ brew cask audit soulver
audit for soulver: passed

Now you can install Soulver. And don't forget to open a pull request 😉

Before you do — check the latest contribution guidelines.

Conclusion

I am really happy that homebrew-cask exists now. It closed a gap in my configuration management. I can set up a new Mac in no time. I hope you enjoy it as much as I do.

How to install 'Settlers II' on Mac OS X

I recently installed "Die Siedler II" on Mac OS X - this is how I pulled
it of.

  • If you don't have the game - go buy it
  • Open WineBottler
  • Create custom prefix
  • Select the .exe file and check one of the DirectX dll's

  • Install it
  • Now right click on the program WineBottler created
  • Open the package
  • Copy the Settlers II folder from Contents/Resources/drive_c/COG
    GAMES/ into another Folder
  • Download BoxerApp

  • Click onto "Import new Game"
  • Drag the Settlers II folder onto the window

  • Thats it! Launch the game!

Well. That's it! Enjoy.

Lock your mac from the command line

During my daily work I try to take breaks and move frequently. In order for
me to leave the room I have to ensure that my computer is locked.

I wrote a little script which does exactly this.

I only have to enter

lock

and my Mac starts to lock.

A nice varitation of this is to use this functionallity together with
my Pomodoro app. It locks my computer after 25 minutes of work for me.
Thats a pretty effective reminder to move 😉

Enough said. Here is the code:

#!/bin/sh
/System/Library/CoreServices/Menu
Extras/User.menu/Contents/Resources/CGSession -suspend  

How to setup your Mac automatically with chef

Recently I joined a team that practices DevOps. That's why I had to learn Chef:

With Chef, you write abstract definitions as source code to describe how you want each part of your infrastructure to be built, and then apply those descriptions to individual servers.

Since I regard my iMac as part of my infrastructure - I decided to give Chef a shot. In this post I explain how I did it.

Bootstrapping chef

Before the first Chef run, you have to prepare youre machine.

I store my cookbooks on Dropbox. So after installing the OS (manually), I download and install Dropbox.

After Dropbox finished syncing I run bootstrap.sh :

USERNAME=shostakovich

mkdir ~/tmp  
cd ~/tmp


# Install GCC + Git

curl https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg > GCC-10.7-v2.pkg  
    sudo installer -pkg GCC-10.7-v2.pkg -target /

# Install chef

sudo gem install chef

# Prepare Directory for Homebrew

sudo mkdir /usr/local  
sudo chown -R $USERNAME /usr/local  

This installs a compiler, Homebrew and some dev-tools like GIT on the machine.

Last but not least bootstrap.sh installs Chef itself.

Installing apps & packages

I have my standard set of tools. Instead of installing them manually I wanted to use Chef.

Luckily there are already cookbooks that can install dmg's and apps within zip files.

You just have to download them and then you can specify which apps to
install:

dmg_package "Google Chrome" do  
  dmg_name "googlechrome"
  source "https://dl-ssl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg"
  action :install
end

zip_app_package "Mou" do  
  source "http://mouapp.com/download/Mou.zip"
end

dmg_package "Virtualbox" do  
  source "http://dlc.sun.com.edgesuite.net/virtualbox/4.1.18/VirtualBox-4.1.18-78361-OSX.dmg"
  type "mpkg"
end  

For all my Unix tools I use the Homebrew cookbook.

This way I can specify all the packages I need in my node.json - the configuration file I use to run chef-solo.

{
  "run_list": [
      "recipe[main]",
      "recipe[git]",
      "recipe[rvm]",
      "recipe[apps]"
  ],

  "packages" : [
     "wget",
     "tmux",
     "watch",
     "mobile-shell",
     "imagemagick",
     "solr",
     "mysql",
     "aspell",
     "htmldoc",
     "ghostscript",
     "redis",
     "pdftohtml"
  ],

  "homedir" : "/Users/shostakovich",
  "user" : "shostakovich"
}

Configuration

I store most of my dotfiles on my Dropbox.

When i set up a new machine i symlink them into my home directory. Last but not least, i change some defaults - for example to move the Dock out of the way..

template "#{node['homedir']}/.vimrc" do  
  source "vimrc.erb"
  owner node['user']
end

execute "set dock to be on left" do  
  command "defaults write com.apple.dock orientation -string left"
  user node['user']
end

execute "relaunch dock" do  
  command "killall Dock"
end  

`

How can you get started?

I highly recommend giving it a shot! It's a good way to learn chef.

For a kick start with chef-solo, watch RailsCast 339.

If you have problems setting up chef-solo on a Mac, have a look at how to fix solo.rb.

If you need further ideas, have a look at the workstation setup of pivotal.

The end

I used this a couple of times already. Its kind of boring, to watch chef setting up your dev-machine. But hey - you can drink coffee in the meantime.

© 2017 Rocu.de

Theme by Anders NorenUp ↑