« Newer Snippets
Older Snippets »
14 total  XML / RSS feed 

Make iTunes arrows point to your own music, not the iTS

defaults write com.apple.iTunes invertStoreLinks -bool YES


This makes those little right-pointing arrows in iTunes point to your library, not the iTunes Store. If you want the iTunes Store, Option-click instead.

opening in a textmate project all files that match a pattern

This will pass all matched filenames to textmate, generating a project with all files flatly in the drawer (no dirs)

egrep -lr pattern * | grep -v .svn | xargs mate

Set disksleep to never

Check out man pmset for further command options!


sudo pmset -a disksleep 0 sleep 0 

Searching with grep & Spotlight's kMDItemDisplayName


# first a grep regex:
# only match the last part of a complete file path

mdfind '*==*' | grep -i -E '/[^/]*?somestring[^/]*?[0-5][^/]*?$' | sed 's/ /\\ /g' | xargs basename


# let Spotlight search for the fixed part of the search string, and grep for the variable one

mdfind 'kMDItemDisplayName == "*somestring*"wc' | grep -i -E '/[^/]*?[0-5][^/]*?$'



# To search for folders add:
mdfind 'kMDItemKind == "Folder" && kMDItemDisplayName == ...' ...


# To search for files you may add, for example:
mdfind '( kMDItemKind == "*text*"wc || kMDItemKind == "*document*"wc || kMDItemKind == "*image*"wc ) && kMDItemDisplayName == ...' ...


# ... or just ...
mdfind 'kMDItemKind != "Folder" && kMDItemDisplayName == ...' ...



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 Terminal.app.



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 http://blog.amber.org/2006/02/27/stupid-textmate-tricks/

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 http://darwinports.opendarwin.org/downloads/DarwinPorts-1.2-10.4.dmg

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.

#!/bin/sh
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'


brilliant!

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:

LIGHTTPD=-YES-


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

-------- Lighttpd
#!/bin/sh
#
# /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
fi

# 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
CONFIG="/etc/lighttpd/lighttpd.conf"
SCRIPT="/usr/local/sbin/lighttpd"

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

StopService ()
{
  ConsoleMessage "Killing Lighttpd Server"
  kill `cat /var/run/lighttpd.pid` 
}

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

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

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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Descriptionkey>
        Lighttpd 1.13</string>
        <key>OrderPreferencekey>
        None</string>
        <key>Provideskey>
        
                Lighttpd</string>
        array>
        Uses</key>
        <array>
                <string>Networkstring>
                Resolver</string>
        array>
        </dict>
plist>


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 »
14 total  XML / RSS feed