TextMate: Search a Current Folder

This is a script for finding a string in files under a current folder in TextMate. It can be very convenient if you know what you are looking is in a particular folder by saving your time searching each file individually or going through a long list of the search result produced by ‘Find in Project’ function.

# Search text in files under the current folder
# by Saophalkun Ponlu
# 15 Jun 2009 | Last Changed 12 Oct 2009

# input dialog box
res=$(CocoaDialog inputbox --title "Search Folder" \
--informative-text "Enter a search string:" \
--button1 "Okay" --button2 "Cancel")

# get the actual search string
SEARCH=$(tail -n1 <<<"$res")

# search and replace regular expression
MATCH="^\([a-zA-Z/._-]*\):\([0-9]*\):\(.*\)"
REPLACE='<li><a href=\"txmt:\/\/open\/?url=file:\/\/\/\1\&line=\2\">\1 (\2)<\/a> <p>\3<\/p><\/li>'

# output styles
echo "
<style>
body { font-size: 12px; }
li { list-style: none; border-bottom: 2px solid #eee; padding: 10px 5px 5px }
li p { color: #333; margin-left: 1.5em; margin-top: .6em; margin-bottom: 1.2em; }
</style>
"


SELECTED_DIR=$TM_SELECTED_FILE

# if the selected item (path) is a file then get its directory instead
if [ -f "$SELECTED_DIR" ]; then
SELECTED_DIR=`dirname $SELECTED_DIR`;
fi

echo $SELECTED_DIR
echo "<h3>You searched for: <em style=\"color: red\">$SEARCH</em></h3>"

# the search process starts
grep -rn --exclude=*.svn-base "$SEARCH" $SELECTED_DIR | sed  "s/$MATCH/$REPLACE/g"

Batch-Resize Photos On Mac

batch resize photos on mac

Normally, I use Photoshop to resize my photos because along with resizing photos I also need to apply some filters. A few days ago one of my friends asked me was there any application on Mac that lets him resize a bunch of photos in one go. He also mentioned that he didn’t wanna apply any filters at all and opening Photoshop takes time (it’s true).

Then I figured out that properly we could do that in Automator (a built-in application for automating repetitive tasks). I had never used Automator before but it’s really easy to use, everything is done by drag and drop. After a minute or so, I came up with a small app that does the job perfectly.

If you need to do that task over and over again, you might wanna check this app out. You can download it here ResizePhotos (946). I don’t need to explain how it works because every step in the app is quite explanatory. Enjoy!

Get A List Of Files On Mac

I just like to share this productivity tip for people who use Mac platform. While I was chatting to Kenno yesterday, he asked me what and how many ebooks I had. I have more than 50 books and if I had to type all the titles of the books or copy&paste the titles one by one it would take me about 5 minutes or so. I just had a feeling that it could be done in one go. So, what I did was selecting all the ebook files and then pasted in a text editor and all filenames were listed just like I thought. I also tried it on Windows Vista and hoped it would work the same way but, unfortunately, it didn’t.