Skip to content

Instantly share code, notes, and snippets.

@avibryant
Forked from pc/safari-bing-patch.rb
Created June 2, 2009 06:37
Show Gist options
  • Save avibryant/122105 to your computer and use it in GitHub Desktop.
Save avibryant/122105 to your computer and use it in GitHub Desktop.
class File
def seek_to(str)
until eof?
start = pos
buf = read(10000)
if(offset = buf.index(str))
seek(start + offset + str.size)
return true
else
seek(start + 5000)
end
end
return nil
end
end
Safari = "/Applications/Safari.app/Contents/MacOS/Safari"
Find = "google.com/%@"
Replace = "bing.com/%@?q=%@\0"
unless File.exists? Safari
$stderr.puts "Couldn't find Safari at #{Safari}"
exit 1
end
File.open(Safari, 'r+') do |f|
$stderr.puts "Scanning #{Safari}..."
if f.seek_to(Find) && f.seek_to(Find)
$stderr.puts "Backing up #{Safari} to #{Safari}.old"
`cp #{Safari} #{Safari}.old`
$stderr.puts "Patching #{Safari}"
f.seek(f.pos - Find.size)
f.write(Replace)
else
$stderr.puts "Couldn't figure out where to apply the patch"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment