Posts for Tag: osx

"Call piped shell commands from Objective-C"

If you happen to want to know how to run - say - the following command from inside an Objective-C application:

echo "something something" | multimarkdown

So that the fantastic [MultiMarkdown]( runs its magic and transforms **something something** into **\something something\**, then you need to do as below:

- (NSString*) convertMD:(NSString *)data {

// Task for echo NSTask *echoTask = [[NSTask alloc] init]; [echoTask setLaunchPath: @"/bin/echo"]; // Tell which command we are running [echoTask setArguments: [NSArray arrayWithObjects:data, nil]];

// Task for multimarkdown NSTask *mdTask = [[NSTask alloc] init]; // Make a new task [mdTask setLaunchPath: @"/usr/local/bin/multimarkdown"]; // Tell which command we are running [mdTask setArguments: [NSArray arrayWithObjects:@"--snippet", nil]];

// Pipes for input and output NSPipe *pipeBetween = [NSPipe pipe]; // Handles getting the result of echo and injecting into md NSPipe *outPipe = [NSPipe pipe]; // Handles getting the result of md

// Rig it together [echoTask setStandardOutput:pipeBetween]; [mdTask setStandardInput:pipeBetween]; [mdTask setStandardOutput:outPipe];

// Execute [echoTask launch]; [mdTask launch];

// And get the result data NSData *result = [[outPipe fileHandleForReading] readDataToEndOfFile];

return [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]; }

A couple of notes here:

- What this does is pipe the result of the echoTask (which will run **echo "\"**) as input (standard) to the mdTask, which will run **multimarkdown --snippet**; - The outPipe will simply take the output of the mdTask so we can return what multimarkdown created; - The commands need the full path in order for the tasks to run; - In case you are curious, i'm creating a markdown editor for OSX with realtime preview inline; - If you want to test this particular piece of code as-is, make sure you [install multimarkdown for OSX first](


'Error compiling pg Ruby gem on OSX'

If you get this error (or similar) while trying to run **bundle install** on one of your Ruby projects or trying to install the **pg** gem:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/void/.rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb --with-iconv-include=/usr/local/opt/libiconv/include --with-iconv-lib=/usr/local/opt/libiconv/lib checking for pg_config... no No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** 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.

The solution is to install the gem like this:

sudo env ARCHFLAGS="-arch i386" gem install pg -- --with-pg-include=/Library/PostgreSQL/8.4/include/ --with-pg-lib=/Library/PostgreSQL/8.4/lib/

**Note:** Replace 8.4 with your installed PostgreSQL version in the above command.

'New keyboard and KeyRemap4MacBook key bindings'

Bought a new keyboard, the DAS Keyboard Professional S. Maybe now i'll finally learn how to code properly :)

Also, took some time to create key bindings for media and brightness controls (for [KeyRemap4MacBook]( for it. Feel free to use my private.xml file and modify as you see fit. The script will only modify keys when the external keyboard is connected. Also, you might need to use the app's EventViewer to change the Vendor and Device ID values :)

I tried to get the sleep key to lock my mac, but i think i'll need to tinker with AppleScript to accomplish that one. Just haven't had the time yet.

Here's the script:

DAS 0x24f0


KeyCode::VK_OPEN_URL_APP_Lock file:///Applications/

DAS Media Volume Mute private.das_vol_mute DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F1, KeyCode::VK_CONSUMERKEY_VOLUME_MUTE

DAS Media Volume Down private.das_vol_down DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F2, KeyCode::VK_CONSUMERKEY_VOLUME_DOWN

DAS Media Volume Up private.das_vol_up DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F3, KeyCode::VK_CONSUMERKEY_VOLUME_UP

DAS Media Play/Pause private.das_play_pause DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F5, KeyCode::VK_CONSUMERKEY_MUSIC_PLAY

DAS Media Prev private.das_prev DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F7, KeyCode::VK_CONSUMERKEY_MUSIC_PREV

DAS Media Next private.das_next DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F8, KeyCode::VK_CONSUMERKEY_MUSIC_NEXT

DAS Brightness Down private.das_brightness_down DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F9, KeyCode::VK_CONSUMERKEY_BRIGHTNESS_DOWN

DAS Brightness Up private.das_brightness_up DeviceVendor::DAS, DeviceProduct::DAS_KEYBOARD __KeyToKey__ KeyCode::F10, KeyCode::VK_CONSUMERKEY_BRIGHTNESS_UP

Lock private.das_lock __KeyToKey__ KeyCode::F12, KeyCode::VK_OPEN_URL_APP_Lock

'Dashlane - Great alternative to 1Password'

If - like me - you are looking for a solution to manage all your passwords, don't feel like spending 50€ on [1Password](, and didn't feel convinced by the [other]( [alternatives](, then you will find joy when you learn about [Dashlane](

It features identity, wallet, and password management, all encrypted on their servers, with automatic web form filling and strong password generation. And ... it's free!

The catch is that, if you want synchronization across all your devices, you need the [premium service]( (about 20 dollars per year) which - in my opinion - is not too bad (by the way, you get to try that for 30 days for free). Considering that with - for example - 1Password you need to pay for updates anyways this seems like a better deal.

Of course - as always - [YMMV](

'GPG Tools for OSX Mail on Mavericks workaround'

If you use [GPGMail]( (look it up if you don't know about email privacy ;)), and migrated to OSX Mavericks preview, then you know it does not work out of the box.

Here's how to trick the operating system to make it work:

- Quit Mail; - Download and [install this fix](; - Run this sequence of commands:

$ sudo defaults write /Library/Mail/Bundles/GPGMail.mailbundle/Contents/Info.plist SupportedPluginCompatibilityUUIDs -array-add "$(grep -A 1 "PluginCompatibilityUUID" /Applications/ | grep string | cut -f 2 -d ">" | cut -f 1 -d "<")" $ sudo chown -R root:staff /Library/Mail/Bundles/GPGMail.mailbundle $ sudo chmod -R ug+r /Library/Mail/Bundles/GPGMail.mailbundle $ sudo chmod 644 /Library/Mail/Bundles/GPGMail.mailbundle/Contents/Info.plist

Keep in mind that on some shells the first command will not work (i.e. [fish]( If that's the case, first switch to another one (bash,sh,csh,zsh) then run the commands.

Restart Mail and it should work.