Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
Showing 21-30 of 30 total

Remove favicons from Safari's cache

Safari caches the favicon for a site the first time it views it, even if the site doesn't have a favicon. This means if one is added later, or it is changed, you'll need to manually remove the cached file. This is pretty simple for a single site:

grep -r  "domain.tld" ~/Library/Safari/Icons/

Then, just remove all the files that match.

grep-based phrase search with Spotlight

Some examples:

# for mdfind "phrase* " and "phrase! " also work, but not "phrase ! "
mdfind -0 -onlyin ~ "phrase This is a" | xargs -0 grep -ails -E 'This is a phrase!'

mdfind -0 "It's just $8.99!" | xargs -0 grep -ails -E "It's just \\\$8\\.99\\!"

mdfind -0 'Fr\303\251d\303\251ric Chopin' | xargs -0 grep -ails -Z -E 'Fr.d.ric Chopin' | \
xargs -0 basename

Regex-based file/folder search with Spotlight

To get more Spotlight search options use mdimport -A and
mdls /somefile.txt in

mdfind -onlyin ~ "*==*" | grep -i -E 'part.*?of.*?name'

mdfind -onlyin ~ '*==* && kMDItemContentType == "text"wc' | \
grep -i -E '.*?txt$'

mdfind -onlyin ~ '*==* && kMDItemKind == "Folder"' | \
grep -i -E '.*?photos.*?[0-5]'

Stop TextMate from writing metadata files (._*)

This stops TextMate from writing it's ._filename metadata files, which can be annoying in mixed environments.

Not mine - from

defaults write com.macromates.textmate OakDocumentDisableFSMetaData 1

Mount and install OS X packages from the command line

If you need to install a .pkg application wrapped in a .dmg file from the command line (say, if you only have SSH access to the machine) there are a few command line utilities that will let you do this. For instance, let's say you're trying to install DarwinPorts on a remote OS X box.

cd ~/Desktop

curl -O

hdiutil attach DarwinPorts-1.2-10.4.dmg

cd /Volumes/DarwinPorts-1.2/

sudo installer -pkg DarwinPorts-1.2.pkg -target "/"

hditutil detach /Volumes/DarwinPorts-1.2/

In a nutshell, this 1) goes to your Desktop folder 2) grabs DarwinPorts from the opendarwin site 3) mounts the dmg 4) goes to the newly mounted DarwinPorts volume 5) installs the package, targeted to the root, as the root user 6) ejects the mounted disc image.

get rid of mac's ._ meta files on unix command line

When a mac accesses storage not formatted in it's own HFS format, it stores it's additional metadata about the file in another file named the same but starting with "._" It can be annoying and when you're accessing a remote volume that's source control managed with subversion, they show up your status information. This bash shell script will get remove of all ._metadata files residing below the current working directory.

for i in `find . -regex '.*\._.*'`; do rm $i; echo "removing $i"; done

If you save that as "/home/$USER/bin/cleanup" and do a "chmod 777 /home/$USER/bin/cleanup" it will be available next time you open a terminal by just typing "cleanup".

Mute Remote Macintosh

Sometimes I am in bed and too lazy to get out to mute my G5. I can just grab my iBook, SSH into the G5 and run the following command:

osascript -e 'set volume output muted true'


Fried mac 'n' cheese

Recipe Summary
Difficulty: Easy
Prep Time: 20 minutes
Cook Time: 5 minutes

Leftover baked macaroni and cheese, refrigerated for at least overnight
1 cup all-purpose flour
1 teaspoon salt
1 teaspoon pepper
1 teaspoon cayenne
1 egg beaten with 2 ounces water
1 cup panko bread crumbs
Oil for deep frying, preheated to 375 degrees

Cut refrigerated macaroni and cheese into slices or bite size pieces.
Season the flour with salt, pepper and cayenne. Dredge each piece through the flour and gently tap off excess. Dip in the egg wash and then coat with the bread crumbs. Allow them to rest for 5 minutes so the crust can set. Very carefully drop into the oil and fry until golden brown. Remove to a baking sheet fitted with a rack and rest for 2 minutes before serving.

(c) Food Network, Alton Brown

Search for open files that won't allow you to unmount a server volume

lsof | grep "Office Server"

Lists out all open files on a given volume ("Office Server" in this case.) Good to find those peskey open files that won't let you eject a mounted network volume.

lighttpd as a startup item on os x

Create the /Library/StartupItems/Lighttpd directory, put both the Lighttpd (chmod +x) and the StartupParameters.plist (I don't really know what this does at all) files into the directory. (this is on jaguar, before the new launchd came out in tiger).

Then add the following line to /etc/hostconfig:


You can start, stop and restart lighttpd using /Library/StartupItems/Lighttpd (start|stop|restart) now, and it will startup when OS X boots.

-------- Lighttpd
# /Library/StartupItems/Lighttpd/Lighttpd
# Script to startup lighttpd with OS X booting.
# OS X 10.3 Jaguar
# modified by kjell olsen
# adapted from the startup mysql
# (c) 2003 MySQL AB
# Written by Lenz Grimmer 

# Suppress the annoying "$1: unbound variable" error when no option
# was given
if [ -z $1 ] ; then
        echo "Usage: $0 [start|stop|restart] "
        exit 1

# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common

# change config and script to match your machine's lighttpd config and lighttpd

StartService () 
  if [ "${LIGHTTPD:=-NO-}" = "-YES-" ] ; then
    ConsoleMessage "Starting Lighttpd Server"

StopService ()
  ConsoleMessage "Killing Lighttpd Server"
  kill `cat /var/run/` 

RestartService ()
        ConsoleMessage "Restarting Lighttpd server"
        /Library/StartupItems/Lighttpd/Lighttpd stop
        /Library/StartupItems/Lighttpd/Lighttpd start

if test -x $SCRIPT ; then
        RunService "$1"
        ConsoleMessage "Could not find lighttpd startup script!"

Be sure to change $SCRIPT + $CONFIG to work with your own lighttpd.

-------- StartupParameters.plist
<?xml version="1.0" encoding="UTF-8"?>
DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
        Lighttpd 1.13</string>

Again, I'm not exactly sure what this does. I copied it from the MYSQL one and changed the description and provider, left "uses" alone.
« Newer Snippets
Older Snippets »
Showing 21-30 of 30 total