OS X – Upon my shoulder http://www.uponmyshoulder.com/blog // TODO: insert witty tagline Tue, 20 Jun 2017 20:25:30 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 Keep GimmeSomeTune running http://www.uponmyshoulder.com/blog/2011/keep-gimmesometune-running/ http://www.uponmyshoulder.com/blog/2011/keep-gimmesometune-running/#comments Fri, 23 Dec 2011 10:45:31 +0000 http://www.uponmyshoulder.com/blog/?p=539 As a follow-up on my previous post on the question, which advocated a simple (but bad) approach to keeping GimmeSomeTune running, here’s a better way!

The Good Thing ™ to do is to use OS X’s built-in mechanism to start and keep processes running, namely launchd.

What we have to do is simply to write a plist containing the info needed by launchd, namely:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>KeepAlive</key>
		<true/>
		<key>Label</key>
		<string>at.eternalstorms.gstlauncherdaemon</string>
		<key>ProgramArguments</key>
		<array>
			<string>/Applications/GimmeSomeTune.app/Contents/MacOS/GimmeSomeTune</string>
		</array>
		<key>RunAtLoad</key>
		<true/>
	</dict>
</plist>

Save this as a plist file in ~/Library/LaunchAgents. The name doesn’t really matter, but the best way to keep everything tidy and adhere to OS X’s standards is to call it at.eternalstorms.gstlauncherdaemon.plist.

Alright! Now GimmeSomeTune is going to start when you log in, and launchd will make sure it keeps running (i.e. relaunch it if it crashes). To tell launchd to use that plist file right now without having to log out and back in again, run:

launchctl load -w ~/Library/LaunchAgents/at.eternalstorms.gstlauncherdaemon.plist

And conversely, to stop it:

launchctl unload -w ~/Library/LaunchAgents/at.eternalstorms.gstlauncherdaemon.plist
]]>
http://www.uponmyshoulder.com/blog/2011/keep-gimmesometune-running/feed/ 1
Deep sleep on MacBook Air Late 2010 http://www.uponmyshoulder.com/blog/2011/deep-sleep-on-macbook-air-late-2010/ http://www.uponmyshoulder.com/blog/2011/deep-sleep-on-macbook-air-late-2010/#comments Tue, 14 Jun 2011 20:14:21 +0000 http://www.uponmyshoulder.com/blog/?p=447 Apple’s latest MacBook Air boasts to last 30 days on battery when sleeping. Classical sleep will power down most of the machine (display, processor, hard drive, etc) but keep the RAM powered on in order to keep the state of the OS. However, the RAM drains too much power to realistically allow more than a week or so on a single charge.

The MBA feat is achieved through “deep sleep”, i.e. writing the RAM contents to a file on the hard drive, which allows powering down the RAM without losing state (also known as hibernation). The only problem is that waking the computer up requires loading back all of this data on RAM, which takes a few seconds.

Apple even uses a trickier approach by default: the computer sleeps normally at first, and switches to deep sleep after a certain amount of time.

This is very easy to see on the MBA: close the lid and reopen it a few minutes later, waking up is super fast. Leave it sleeping for a day, and it will take about ten seconds before you can do anything with it.

While this is a clever solution, the parameters aren’t that well adjusted — the computer goes to deep sleep too fast in my opinion.

This can be modified through pmset. First, run it to see what are the active parameters:

Air:~ florent$ pmset -g
Active Profiles:
Battery Power		-1*
AC Power		-1
Currently in use:
 deepsleepdelay	4200
 halfdim	0
 hibernatefile	/var/vm/sleepimage
 disksleep	10
 sleep		10
 hibernatemode	3
 displaysleep	5
 ttyskeepawake	1
 deepsleep	1
 acwake		0
 lidwake	1

The interesting one is deepsleepdelay (edit: see footnotes). It represents the time in seconds before switching from classical sleep to deep sleep. 4200 seconds, 70 minutes, is way too short. Let’s set it to 24hrs instead:

Air:~ florent$ sudo pmset -a deepsleepdelay 86400

There it is! Deep sleep will still work, but won’t be as annoying.

Edit July 2, 2011:
It looks like Apple changed the name of that setting from deepsleepdelay to standbydelay during the update to OS X 10.6.8. The command line has to be changed accordingly:

Air:~ florent$ sudo pmset -a standbydelay 86400
]]>
http://www.uponmyshoulder.com/blog/2011/deep-sleep-on-macbook-air-late-2010/feed/ 2
Semibold keyboard shortcut in Pages http://www.uponmyshoulder.com/blog/2011/semibold-keyboard-shortcut-in-pages/ http://www.uponmyshoulder.com/blog/2011/semibold-keyboard-shortcut-in-pages/#respond Thu, 26 May 2011 13:08:08 +0000 http://www.uponmyshoulder.com/blog/?p=440 Continue reading Semibold keyboard shortcut in Pages]]> So… Turns out there is no shortcut to turn text to semibold in Apple Pages, from the iWork suite. There are shortcuts for bold and italic respectively, but not semibold (or light / ultralight for that matter) even for the fonts that support it.

The closest thing to a solution that I found is through Character Style:
– Select a piece of text, make it semibold
– In the Styles Drawer, under Character Styles, click on the little arrow next to “none” and “Create New Character Style From Selection
– Assign a Hot Key to the newly created Character Style, by clicking the arrow next to it and Hot Key.

There are a few drawbacks to this approach, mainly that the character style you’re defining will be tied to a particular font, and that the only shortcuts allowed by the Hot Key setting are F1 to F6. If anyone has a better way, I’m all ears!

]]>
http://www.uponmyshoulder.com/blog/2011/semibold-keyboard-shortcut-in-pages/feed/ 0
Automatically restart applications on OS X http://www.uponmyshoulder.com/blog/2011/automatically-restart-applications-on-os-x/ http://www.uponmyshoulder.com/blog/2011/automatically-restart-applications-on-os-x/#comments Sat, 07 May 2011 08:53:33 +0000 http://www.uponmyshoulder.com/blog/?p=433 I use GimmeSomeTune to provide hotkeys and some other goodies for iTunes. It works alright, but is veeeery crashy — usually every dozen hours or so on my machine.

How to fix that? Let’s relaunch it as soon as it crashes. Simple!

In a terminal:
for (( ; ; )); do open -W /Applications/Multimedia/GimmeSomeTune.app/; done

open is the bash command to launch applications on OS X. It works with all kinds of files: open somefile.avi will open that file in your default video player, VLC for example. The -W flag tells open to wait until the application exits before returning any value. By putting it all in a for loop, we effectively ensure that bash will launch GimmeSomeTune, wait until it crashes, then relaunch it, and so on.

Edit: this is a bad way of doing things. A better way is described here.

]]>
http://www.uponmyshoulder.com/blog/2011/automatically-restart-applications-on-os-x/feed/ 1
nginx as a reverse-proxy to Apache+Sinatra http://www.uponmyshoulder.com/blog/2011/nginx-as-a-reverse-proxy-to-apachesinatra/ http://www.uponmyshoulder.com/blog/2011/nginx-as-a-reverse-proxy-to-apachesinatra/#respond Wed, 27 Apr 2011 22:12:20 +0000 http://www.uponmyshoulder.com/blog/?p=428 I was recently developing a Sinatra app that wanted to host from home — setting it up Heroku would have meant migrating from SQLite to Postgres, and I’m lazy. The problem was that I already happened to have an Apache server at home to serve some other content, specifically some calendars through the WebDAV module.

The solution I used was simple: instead of having Apache listening on port 80, I set up nginx to listen to port 80 and redirect to either Apache (set to listen on port 8080 instead) or Sinatra (port 9393) depending on the URL.

 

Nginx configuration was dead simple (after a few tries). The gist of it being these few lines:

location / {
    proxy_pass   http://127.0.0.1:8080/;
}
location /reorg {
    proxy_pass http://127.0.0.1:9393;
}

The configuration in its entirety is available here.

 

After setting up this solution, I realized Apache’s mod_proxy would have done the trick without the need for nginx. And that mod_rack (Phusion Passenger) could probably have eliminated the need for running a specific ruby process for Sinatra at all. Live and learn!

]]>
http://www.uponmyshoulder.com/blog/2011/nginx-as-a-reverse-proxy-to-apachesinatra/feed/ 0
Convert .approject to .aplibrary http://www.uponmyshoulder.com/blog/2011/convert-approject-to-aplibrary/ http://www.uponmyshoulder.com/blog/2011/convert-approject-to-aplibrary/#respond Thu, 24 Feb 2011 19:32:33 +0000 http://www.uponmyshoulder.com/blog/?p=381 If you ever backed up Aperture projects outside your standard library, you probably noticed the default format for exported albums changed from .approject to .aplibrary in the update from Aperture 2 to Aperture 3.

The Finder correctly reports these new .aplibrary as “Aperture Library”, but it seems to have forgotten everything about the old .approject who now appear as standard folders (it appears to be a weird bug on my machine, but still).

So how do we convert our .approject to .aplibrary?

  • In Aperture 3, pick File > Import > Library/Project… and select your .approject folder. This will effectively re-import your project in the current Aperture Library.
  • Right-click on the project and select Export > Project as New Library…
  • Once it’s done, delete the project from the current Aperture Library (unless you want a backup or if you have other mischievous plans for your pictures, of course)

 

That’s it! Quite straightforward indeed, but a bit puzzling at first.

]]>
http://www.uponmyshoulder.com/blog/2011/convert-approject-to-aplibrary/feed/ 0
Ye old Dock: Leopard-style Exposé under Snow Leopard http://www.uponmyshoulder.com/blog/2011/ye-old-dock-leopard-style-expose-under-snow-leopard/ http://www.uponmyshoulder.com/blog/2011/ye-old-dock-leopard-style-expose-under-snow-leopard/#respond Thu, 27 Jan 2011 19:23:09 +0000 http://www.uponmyshoulder.com/blog/?p=377 Samuel Clay shares an awesome little tweak: replace Snow Leopard’s Dock.app by the Dock.app from a beta version of SL, and Exposé will get back to the way it acted on Leopard, i.e. the size of the thumbnail is proportional to the size of its window.

And it rocks.

]]>
http://www.uponmyshoulder.com/blog/2011/ye-old-dock-leopard-style-expose-under-snow-leopard/feed/ 0
Can’t find the PostgreSQL client library (libpq) http://www.uponmyshoulder.com/blog/2011/cant-find-the-postgresql-client-library-libpq/ http://www.uponmyshoulder.com/blog/2011/cant-find-the-postgresql-client-library-libpq/#comments Wed, 26 Jan 2011 14:19:08 +0000 http://www.uponmyshoulder.com/blog/?p=365 You might encounter this error while trying to install the pg gem (v0.10.1), or when updating from v0.10.

My stacktrace on Mac OS X Snow Leopard 10.6.6 with Rubygems 1.4.2, Ruby 1.8.7 and Postgres 9.0.2 was the following:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Oookay, so let’s try to find out what’s going wrong. A quick Google search shows that errors like this one happens on Linux too, and usually suggests that ARCHFLAGS definitions may be a problem. Indeed, /Library/Ruby/Gems/1.8/gems/pg-0.10.1/ext/mkmf.log contains this error message:

ld: warning: in /usr/local/Cellar/postgresql/9.0.2/lib/libpq.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

The problem seems to come from the way Homebrew installs Postgres.

Homebrew install notes include the following informative message:

If you want to install the postgres gem, including ARCHFLAGS is recommended:
    env ARCHFLAGS="-arch x86_64" gem install pg

There! Now the only problem is if you install your gems as root, you can’t merely put a sudo before the “gem”, but you have to sudo su then execute the command:

Air:~ florent$ sudo su
Password:
sh-3.2# env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.10.1
1 gem installed
Installing ri documentation for pg-0.10.1...
Installing RDoc documentation for pg-0.10.1...

Voilà!

Edit 18 Dec. Chad provided a simpler solution in the comments that doesn’t require you to log in as root and works just as well:

sudo env ARCHFLAGS="-arch x86_64" gem install pg
]]>
http://www.uponmyshoulder.com/blog/2011/cant-find-the-postgresql-client-library-libpq/feed/ 14
Tunalysis – analyse your iTunes music library http://www.uponmyshoulder.com/blog/2010/tunalysis-analyse-your-itunes-music-library/ http://www.uponmyshoulder.com/blog/2010/tunalysis-analyse-your-itunes-music-library/#respond Sun, 21 Nov 2010 15:19:46 +0000 http://www.uponmyshoulder.com/blog/?p=329 Tuna

Tunalysis is a small(ish) Ruby script that will read your iTunes library, crunch numbers, and gives you a few interesting facts about it, such as:

  • Total number of songs
  • Total number of playlists
  • Average song length
  • Average bitrate
  • Average play count
  • Average skip count
  • Total time spent listening to music

Some of these statistics are already available in iTunes, but Tunalysis ultimate goal is to expand iTunes (limited) stats and to give you hindsight on your musical habits and tastes.

Tech

Tunalysis is written in Ruby and uses Bleything’s plist to parse iTunes’ XML library.

At the time being, Tunalysis only works on OS X. I’m not planning to do a Windows port, but will gladly accept a patch if you do. :)

Tunalysis is licensed under the GPLv3.

Features to come

  • You don’t like that: suggest music to delete based on the skip count, the play count, and the last played date
  • Preferred artists (by number of songs)

I’m open to suggestions. If you’re interested in a particular piece of data, leave a comment or send me an email and I’ll add it.

Get Tunalysis on GitHub!

]]>
http://www.uponmyshoulder.com/blog/2010/tunalysis-analyse-your-itunes-music-library/feed/ 0
A bit of Terminal-fu http://www.uponmyshoulder.com/blog/2010/a-bit-of-terminal-fu/ http://www.uponmyshoulder.com/blog/2010/a-bit-of-terminal-fu/#respond Thu, 11 Nov 2010 20:59:46 +0000 http://www.uponmyshoulder.com/blog/?p=320 Yesterday, my little brother was typing something on a linux bash and suddenly went back to the beginning of the line with a simple Ctrl-a. It blew my mind.

I don’t know why, but it never occurred to me to look for shortcuts in Terminal (and bash in general), other than Ctrl-c for badly behaving processes. I just cursed myself and frantically typed on the left arrow key each time I typed cd instead of cp.

Turns out bash has plenty of them, and here are a few useful ones I’m really glad to know now:
Beginning of the line: Ctrl+a
End of the line: Ctrl+e
Delete the word under the cursor or before: Ctrl+w
Delete all chars before the cursor: Ctrl+u
Delete all chars after the cursor: Ctrl+k

Apparently these shortcuts work in a lot of text fields, everywhere.

You can also move the cursor word-by-word by typing Esc, then f or b. It’s not really practical though, so you’d be better of remapping the following keys in Terminal Settings > Settings > Keyboard:
control cursor left: \033b (\033 is actually Esc)
control cursor right: \033f

Now you can swiftly move word-by-word with Alt+left arrow and Alt+right arrow.

I guess the lesson here is there’s always to learn from your siblings — especially the geeky ones.

]]>
http://www.uponmyshoulder.com/blog/2010/a-bit-of-terminal-fu/feed/ 0