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")
if 'Ruby' =~ /^ruby$/i then
print("'Ruby' =~ /^ruby$/i true \n")
if 'Ruby'.casecmp('ruby') == 0 then
print("'Ruby'.casecmp('ruby') true \n")

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

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 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
tell application "System Preferences"
set current pane to pane ""
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 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.

⌘ ⇧ 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 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

Bash Double Quotes Single Quotes

When working on the command line some scripts/programmers seem to arbitrarily switch between "Double Quotes" and 'Single Quotes'.

The difference in bash at least is
Double quotes evaluate variables inside of them.
Single quotes are a literal string (NO evaluation).

computer ~ $ fred=result
computer ~ $ echo "fred is $fred"
fred is result
computer ~ $ echo 'fred is $fred'
fred is $fred and firefox 3 cookies

Since upgrading to Firefox 3 when logging into then viewing my own blog at I no longer had the options in the top right corner to add new posts and the edit button at the bottom of my posts.

This was due to the fact that I have disabled 3rd party cookies, which meant that my credentails for being logged into could not be read by

By adding to the allowed list I now remain logged in when viewing my blog on Is this a security risk can any site now read my cookies?

Here is the setting that got it working again.

Sunday, 14 September 2008

Setting up the terminal

This was something I discovered a long time ago and could not find an earlier entry about it.
Certain Mac OS X terminal programs read the properties from the ~/.bash_profile and some fom the ~/.bashrc.

NB: ~ means the users home directory. and files beginning with a dot '.' are hidden files in unix speak. Something rc often refers to configuration files for the something program.

A good soloution to the problem is to make .bash_profile load your .bashrc, like so

if [ -f ~/.bashrc ]; then
. ~/.bashrc

A very basic .bashrc file would look something like

#.bashrc file for users terminal /command line preferences
# This is a comment. MAC-UK keyboards type alt-3 for a # character

#Add a shared scripts folder to the Path
export PATH=$PATH:/Users/Shared/Scripts/

#make ls look pretty with colours (list your files)
alias ll='ls -l -FG'
alias ls='ls -AFG'

Friday, 12 September 2008

Twitter to update Facebook Status

Found this Facebook app to allow Twitter tweets to appear as your Facebook status

Install plugin (above link), enter twitter account details, then select allow status updates.

Read about in the article

Tuesday, 9 September 2008

An Applescript Preference Systems

I found the basis for an applescript preference systems at macosxhints.
I have corrected a few typos and here it is.

tell application "Finder"

end tell

Preference system version 1

Chris J. Shull

The code is free. Re-use at will, but please leave this acknowledgement in your code.
Feel free to email me and tell me you've found it helpful!

---Base prefs snippet
set prefname to "net.munkymorgy.pref" --this will be the filename
set prefcontent to "default" --this will be the content of the pref file. NOTE that you can create multiple lines
set prefpath to FindPrefFolder() --finds the path to the user's Prefs folder
set ContentParaNumber to 1 --is the paragragh that will be found in a single preference finder. change it throughout the script to switch paragragh found
---End of Base

--write prefs snippet (overrides original)
if CheckIfExists(prefname, prefpath) is true then DeleteAFile(prefname, prefpath)
MakeAFile(prefname, prefcontent, prefpath)
display dialog (prefpath & " " & prefname)
--end write prefs

---read Prefs snippet
if CheckIfExists(prefname, prefpath) then
set pref to paragraph ContentParaNumber of ReadAFile(prefname, prefpath)
set ThereArePrefs to true
set ThereArePrefs to false
end if
if ThereArePrefs then display dialog pref --or whatever you want
---End read

on UnixfyPath(stringer, origchar, newchar)
set the testlist to the text items of the stringer
repeat with letter in testlist
set let to letter as string
set orig to origchar as string
if let is orig then
set the contents of the letter to newchar
end if
end repeat
set the newpath to "/" & (the testlist as text)
return the newpath
end UnixfyPath

on MakeAFile(filename, filecontents, folderpath)
tell application "Finder"
do shell script ("echo \"" & filecontents & "\" | cat > \"" & folderpath & "/" & filename & "\"")
end tell
end MakeAFile

on ReadAFile(filename, folderpath)
tell application "Finder"
set filecontent to do shell script "cat \"" & folderpath & filename & "\""
end tell
return filecontent
end ReadAFile

on DeleteAFile(filename, folderpath)
tell application "Finder"
do shell script "rm \"" & folderpath & filename & "\""
end tell
end DeleteAFile

on CheckIfExists(filename, folderpath)
tell application "Finder"
set folder_cmd to ("find \"" & folderpath & filename & "\"")
do shell script folder_cmd
set worked to true
on error
set worked to false
end try
end tell
return worked
end CheckIfExists

on FindPrefFolder()
tell application "Finder" to set libpath to path to home folder
set userName to do shell script "whoami"
set UnixPath to UnixfyPath("Users:" & userName & ":", ":", "/")
set prefpath to UnixPath & "Library/Preferences/"
return prefpath
end FindPrefFolder


Turning applescripts into apps

This may seem very simple to those have done it before but it took me a while to figure it out.

Once you have written your applescript and saved it as normal.

File -> Save As and change format to application.
When it is saved it will be a *.app