Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

Tuesday, February 19, 2019

Replacing text using sed on OSX

Yet another reminder post for my self.

One again is bumped into the error message

sed: 1: "test.txt": undefined label 'est.txt'

when trying to replace text in a file using sed. When using sed on OSX to replace text in files, using -i, the BSD variant of sed on OSX requires an extension parameter, where a copy of the original file saved.

The syntax is as following

sed -i '.bak' 's/before/after' file.txt

If you are sure of what you are doing you can leave the extension parameter empty and not having a backup.

sed -i '' 's/before/after' file.txt

As a reference, here is the syntax for the GNU variant, ie. Ubuntu and friends

sed -i 's/before/after' file.txt

Tuesday, December 22, 2015

Screenshots in OSX

This is mostly for my own convenience, since I always forget the screenshot key combinations for doing the various kinds of screenshots you can do in OSX.

  • Command + Shift + 3 : Take screenshot of the whole screen
  • Command + Shift + 4 : Take screenshot of a part of the screen
  • Command + Shift + 4 : Press Space and select window to take screenshot of
The command for taking a screenshot of a window also works on open menus.

Appels official documentation: https://support.apple.com/en-us/HT201361

Make Alt + left/right work in iTerm2

I recently got a new harddrive, SSD!!!! So I made the decision to wipe the slate and did a clean install. But as always not every thing worked as before, as always. One of the most annoying things was that Alt + left arrow did not jump one word to the left and vide versa for Alt + right arrow. This is OSX default behaviour, on Linux it is Ctrl + arrow keys.

Anyway, to solve this you need to change what iTerm sends when you hit the key combination. Quickest way is to change set keys shortcuts for the default profile to "xterm Defaults"
Next you need to set the correct key bindings in your .inputrc, .bashrc etc. The file depends on how you set up your system. I cannot remember what file is standard on OSX, but i have my config stuff in a .bash_profile to avoid polluting the system more the needed. So i put the following two lines in my .bash_profile

bind '"\033[1;9D": backward-word'
bind '"\033[1;9C": forward-word'

Reload your config file or open a new terminal and I have Alt + arrow keys back working.

Have a look at http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2 also.

Wednesday, August 12, 2015

Spotify web player keyboard shortcuts

It seems that the keyboard shortcuts for the Spotify web player are different based on OS and browser!!! And it looks like they tend to change a bit over time!! Thank you Spotify.

These work on OSX with Chrome (I am on a danish keyboard, not sure if this have anything to say)

Space - Play/Pause
Shift+Right arrow - Next track
Shift+Left arrow - Previous track
Shift+Ctrl+Right arrow - Forward in track approx. 15 sec
Shift+Ctrl+Right arrow - Backwards in track approx. 15 sec
Ctrl+Alt+s - Open search
Ctrl+Alt+Up arrow - Increase volume (not above system volume)
Ctrl+Alt+Down arrow - Decrease volume

Any I missed??

UPDATE

You need to have focus i the actual player for the shortcuts to work. So you need to click in the right side player for the keyboard shortcuts to work.

Tuesday, April 1, 2014

No DNS search domain for SSH after Mavericks upgrade

I often access a lot of server via SSH that all resides on the same domain. So I have set up a the as a search domain. Since I am on OSX I have do do this via the Network preference GUI. To add a search domain edit the connection, hit the DNS tab and a  the domain you want to autocomplete from. This will add the search domain to your resolve.conf, that is automatically generated on OSX. If you are on other *NIX systems, just edit your resolve.conf and add

search example.org

This will, after reload, enable you to ssh to a host under the search domain without specifying the full hostname, ie.

$ ssh root@host

will try to connect  to host.example.org.

For some reason this does not work out of the box on OSX after the Lion release. And it was again broken after I upgraded to Mavericks. Apparently the search domain is not used. Thank to Google I found this which helped my resolve the problem.

To fix the problem edit /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist and add the following key

<string>-AlwaysAppendSearchDomains</string>

to the array under ProgramArguments. After a restart of the DNS service by doing

$ sudo launchctl unload -w System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

SSH should complete hostnames from the search domain.

Wednesday, June 6, 2012

Installing PCNTL for PHP on OSX Lion

Today I needed to install the PCNTL extension for PHP for a tutorial session at the Dutch PHP Conference. And since I am working on OSX Lion, this of course gave some problems due to the rather odd installation of Apache and PHP on OSX.

Several sites on the web gave quick guides for this, but still, as always there are a few things you need to keep in mind for it all to work. I will try to walk through the process as detailed as possible:

First start by installing Xcode. You can get the latest version from the App Store. NOTE that the App Store only have the latest version of Xcode, so if you need a version for Snow Leopard or older, you need to dig deep on the web (https://connect.apple.com is a good place to start).

Next you need to install the Command Line Tools from Xcode. You do this by opening Xcode, go to Preferences (CMD + ,) -> Downloads -> Components and hit install on the Command Line Tools. You can get the Command Line Tools without installing Xcode via https://connect.apple.com

Now you need to find out what version of PHP is installed on OSX

$ php -v
PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 20 2012 22:55:53) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

and then get the source code for that version

$ curl -O http://us.php.net/distributions/php-5.3.10.tar.gz

When the download have finished, you should unpack, find the PCNTL extension, phpize, configure, make and then make install

$ tar -xzvf php-5.3.10.tar.gf
$ cd php-5.3.10/ext/pcntl
$ phpize
$ ./configure
$ make
$ sudo make install

If phpize is complaining, you are probably missing autoconf. The easiest way to install autoconf is via Homebrew. You install Homebrew by doing

$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

The first thing you need to do afterwards is to run

$ brew doctor

to find out if any dependencies are missing. Homebrew will telle you what to do, if any is missing.

Lastly you need to enable the PCNTL extension. Do this by adding the following to your php.ini

extension=pcntl.so

if you do not know where your php.ini file are, you probably need to create on, by doing

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Restart Apache and verify that the PCNTL extension are loaded correctly

$ sudo apachectl restart 
$ php -m | grep pcntl 
pcntl

If the PCNTL extension for some reason is not loaded, try and copy the pcntl.so from the compiled source code to the extensions directory

$ sudo cp php-5.3.10/ext/pcntl/modules/pcntl.so /usr/lib/php/extensions/no-debug-non-zts-10090626/

Restart apache and verify the the PCNTL extension is loaded.

Resources:

Tuesday, January 17, 2012

An odd error with VirtualBox on OSX 10.6

I recently updated my version of VirtualBox on my OSX 10.6 box to version 4.1.8 and it suddenly stopped working. When I tried to start on of the virtual I was given the following error message:

Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE).


After searching the Internet a bit I found a highly unusually solution. Remove write permission for Other!!

$ chmod o-w Applications

Why this work, I do not know but it does. If you know why, please leave a comment.