Twitter Updates

Tuesday, 23 September 2008

Search for files NOT containing text

I have been trying to use grep to find files that dont contain certain text.
And well it has not been going so well, to find files that contain text is easy
$grep -il text *.txt
To invert a grep search just add the option -v, that will be the non matching files?
$grep -ilv text *.txt
What actually happens is it is searching line by line, and invariably the .txt file has more than one line that does not contain the 'text'.
What you actually want to do is find all the files that match (because that is easy) then print out a list of files omitting all the ones that match.
So here is a short ruby script to do just that:
I called the script ruby_find.rb
and call it using $ruby_find.rb text

Ruby case-insensitive test

Three Ruby methods for case insensitive string matching.
'Ruby' can be replaced by any String or variable of type string

if 'Ruby'.downcase == 'ruby' then
print("'Ruby'.downcase == 'ruby' true \n")
end
if 'Ruby' =~ /^ruby$/i then
print("'Ruby' =~ /^ruby$/i true \n")
end
if 'Ruby'.casecmp('ruby') == 0 then
print("'Ruby'.casecmp('ruby') true \n")
end

Wednesday, 17 September 2008

Replacing Macbook Hard Drive

Since I saw some 500GB 2.5" SATA Hard Drives I have been thining about repacing my 160GB HD. Instructions on replacing macbook drive can be found here http://www.macinstruct.com/node/130

Unfortunately macbooks (as of 2008) only allow 2.5" drives upto a height of 9.5mm. the new 400GB and 500GB 2.5" form factor drives use 3 disc platters in stead of the standard 2 and are 12.5mm in height, therefore will not fit in the macbooks :-(

Looks like the current biggest that will fit are the 320GB which can currently be found for £50

MAC OS X 10.5 Leopard changing spaces with one hand

I really like Spaces on Leopard but some times when walking around with my macbook I cant use ctrl-cursors to change spaces and would like a really nice way to change Spaces with one hand. I could show spaces in the menu bar but that is getting a bit cluttered.

If I could use the accelerometer and just tap the side of the monitor to change Spaces that would be nice, the next best thing I have found is Warp http://www.ksuther.com/warp/ which pops up a preview of the next space when the mouse hits the edge of the screen.

Mac OS X Full Screen Button

While I have not quite got this one cracked yet I found a script that came close.
The script is the equivalent of pressing the top left + window button. which toggles the window between its optimised size and the last user defined size.

I also have quick silver installed and added ctrl-m to trigger the script.
I keep the script in ~/Scripts
maximise app.scpt


tell application "System Events"
if UI elements enabled then
set FrontApplication to (get name of every process whose frontmost is true) as string
tell process FrontApplication
click button 2 of window 1
--button 2 is the green "zoom" button for all applications
--window 1 is always the frontmost window.
end tell
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Check 'Enable access for assistive devices'"
end tell
end if
end tell


----
I did not write the script and unfortunately cant remember where I got it to credit the writer. If you know the original source let me know.
----
if it does not run you probably need to set the execurtable permission from the terminal
cd ~/Scripts
chmod u+rwx maximise\ app.scpt

Mac OS X Screen Capture

For the Firefox 3 and blogger.com post I wanted to include a screen grab of the settings I was using. I discovered that this is very easy on OS X I used the site below to quickly find the keyboard shortcuts.

http://www.ss64.com/osxsyntax/keyboard.html

⌘ ⇧ 3 Screen to png file on desktop
⌘ ⇧ 4 + Drag: Selection to png file on desktop
⌘ ⇧ 4 + Spacebar: Window (click camera) to png file

It is possible to change the output format by typing the following at the terminal
$defaults write com.apple.screencapture type jpg
$killall SystemUIServer

Tuesday, 16 September 2008

Mac OS X Default $PATH

Just in case the $PATH terminal variable gets corrupted, for MAC OS X 10.5 .
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin