Force-update text shortcuts in OS X Yosemite

My text shortcuts never synced when I recently set up my new Macbook and so I was left inserting all my emojis using ctrl+space and using my mouse like you would if you weren’t communicating primarily by thumbs-up emoji like me 👍🏼

So, to force a refresh:

  1. Turn off iCloud Drive
  2. rm -rf ~Library/Mobile Documents/com~apple~TextInput
  3. Turn iCloud Drive back on

Open every link in Safari's Reading List in tabs

Use Safari’s Reading List as an inbox.

When you come across some link or page that you would like to look into at some point just not right now, hit cmd+shift+d on your mac or use the share sheet available almost everywhere on your iOS device and add it to Reading List.

Then when the time is right explode that thing into separate tabs and purge through them.

#!/usr/bin/env ruby
# $ gem install CFPropertyList
require 'cfpropertylist'

path = File.expand_path '~/Library/Safari/Bookmarks.plist'
plist = CFPropertyList::List.new file: path

list = plist.value.value["Children"].value.select do |item|
  if title = item.value["Title"]
    title.value == 'com.apple.ReadingList'
  end
end.first.value["Children"].value

bookmarks = list.map do |item|
  item.value["URLString"].value
end.reverse

puts "Opening #{bookmarks.count} tabs "

bookmarks.each do |url|
  `osascript -e 'tell application "Safari" to tell window 1 to make new tab with properties {URL:"#{url}"}'`
  print '.'
end

puts ''

Clear all items in Reading List and just re-add any linkif you’re still undecided about it.

The script also works perfectly inside Run Shell Script in Automator if you want a .app.

foundation-grid

For years I’ve been using ZURB’s Foundation as a starting point for new sites. It’s really great — but also kind of huge. And the internals are very advanced so picking out parts isn’t as easy as it probably could be. But here’s the grid for your blocky pleasure:

screenshot

Get it: foundation-grid

blank

Oh, where do I even start.

Now and then I like to sport a completely stripped down Safari, hiding the toolbar and everything else:

Stripfari

Look at that! Just the content. Just me and my one million tabs. Only problem: when I make a new tab, the address bar isn’t focused as it is, when the toolbar is visible. So you need to press cmd + l yourself like an animal.

So we make a start-page for new tabs. But there’s no api for focusing the browser chrome. But there is AppleScript (there’s always AppleScript).

We’ll just make a tiny server that serves a page with one button that it clicks itself. And then make that button call some Applescript. That’s definately not an insane solution to a very serious problem.

Sounds good? You should try it out.

Make Github responsive with 9 lines of CSS

My browser windows are seldomly as wide as Github’s layout. This works great for most of the websites that I visit - yay responsive - but Github’s layout is still too wiiiiiiide.

Taking matters into my own hands I opened up Web Inspector and found out that you can make it (naively) responsive with relatively few lines of css:

Please do fork it and improve it.

Getting your locales in line before going on your dokku adventure

Update 2015-05-12: Seems the correct file to edit is /etc/default/locale:

export LANGUAGE="en_US.UTF-8"
echo 'LANGUAGE="en_US.UTF-8"' >> /etc/default/locale
echo 'LC_ALL="en_US.UTF-8"' >> /etc/default/locale

Then reboot.


I’m really digging dokku-alt. Dokku is a simple way of setting up a deployment setup as easy as Heroku’s. Dokku-alt is that plus some bundled plugins.

I had some troubles though with the Postgresql databases being created with ASCII encodings. So before you install and setup dokku get your locales in order - make your /etc/locales look like:

LANG=en_US.utf-8
LANGUAGE=en_US.utf-8
LC_CTYPE="en_US.utf-8"
LC_NUMERIC="en_US.utf-8"
LC_TIME="en_US.utf-8"
LC_COLLATE="en_US.utf-8"
LC_MONETARY="en_US.utf-8"
LC_MESSAGES="en_US.utf-8"
LC_PAPER="en_US.utf-8"
LC_NAME="en_US.utf-8"
LC_ADDRESS="en_US.utf-8"
LC_TELEPHONE="en_US.utf-8"
LC_MEASUREMENT="en_US.utf-8"
LC_IDENTIFICATION="en_US.utf-8"
LC_ALL=en_US.utf-8

Source it (or reboot) and then set up dokku.

Install Qt on OS X Yosemite (Beta 3)

To install Qt on Yosemite (Beta 3 right now) using homebrew, just act as if you’re on Mavericks and it will work fine:

Edit /usr/local/Library/Homebrew/os/mac/version.rb:

def to_sym
  return :mavericks # <-- stupid hack.
  SYMBOLS.invert.fetch(@version) { :dunno }
end

Then when you’re done; clean up after yourself!

Rename current TMUX session to current directory's basename

I like having a seperate TMUX session per project I’m currently working on. So a numbered list of sessions quickly becomes unhandy.

tmux rename-session `basename $(pwd)`

ctrl-b s and we get this:

(0) + angular-firmafon: 1 windows (attached)
(1) + blog: 3 windows (attached)
(2) + wallboard: 2 windows

Bonus tip: Put bind ^S switch-client -l in your .tmux.conf. Now ctrl-b ctrl-s toggles between the current and last session.

Open photo GPS location in Apple Maps using ruby

Dr. Drang posted a lengthy article and script to open a given photo’s EXIF GPS location in Apple Maps. He’s using python and a library called “PIL”. I liked the idea but couldn’t, no matter what I tried, get the damn thing to install and what is python anyway? I like ruby! I’m sure there’s an easier way?

Turns out there was.

The rubygem exifr reads EXIF data like a champ, so let’s get it:

$ sudo /usr/bin/gem install exifr

I’m using the absolute path to gem, because we want to end up using this as a system service, and system services use system ruby.

Now, here’s the script. Save it as something like ~/bin/map.rb:

#!/usr/bin/env ruby
begin
  require 'exifr'
rescue LoadError
  require 'rubygems'
  require 'exifr'
end

usage = <<-USAGE
usage: map.rb IMAGE_PATH
USAGE

path = ARGV.shift

if path.nil?
  puts usage
  exit(0)
end

exif = EXIFR::JPEG.new(path)
if coords = exif.gps
  system "open 'http://maps.apple.com/?q=#{coords.latitude},#{coords.longitude}'"
else
  puts "No GPS data for #{path}"
end

Remember to chmod +x it and call it like the Doctor does in a service like this, substituting the path to where you saved the script:

Update Safari from vim with AppleScript

When Livereload is too much and cmd-tab’ing too little, there’s always this AppleScript.

#!/bin/sh
osascript -e 'tell application "Safari"
  set _url to URL of current tab of front window
  set URL of current tab of front window to _url
end tell'

Put it in your PATH, chmod it +x, and map it to what you like in vim:

map ,r :call system("update_safari.sh")

You could even auto-run it when you save the current buffer:

autocmd BufWritePost <buffer> :call system("update_safari.sh")

Replace <buffer> with * to do it in every buffer.