Sunday, February 20, 2011

Automator - Get folder name using Shell Script


I wanted to move a folder from Movies to Music and rename both the folder and the videos.

Challenge was to 
1) Pass output of previous action to shell script.
2) Get the folder name.

#1 Passing output of previous action to shell script
Once you drag and drop Utilities/Run Shell Script action and change drop down "Pass Input" to "as arguments", it becomes evident that the values are passed in the usual way command line variables are passed to a shell script in Unix. i.e. in $@

If you see in the automator workflow above, I'm getting all the file names in the folder as $@ in my script. You might know that we can access the contents of $@ as $1, $2 etc and $# gives the total number of variables, in this case number of files.

Here's how I went over the list of files and renamed them all.

#Say for example $@ has "/Users/ruchi/Movies/Snowboarding 2010/videofile1.AVI /Users/ruchi/Movies/Snowboarding 2010/videofile2.AVI"
while [ ! -z "$1" ]
do
mv "$1" "`echo "$1" | sed 's/\[[aA-zZ,.]*\] [aA-zZ, ]* - [0-9][0-9] - //g'`"
shift
done

#2 Getting the folder name
This is more of a hack. I already had file names with path in #1, I checked the depth of my the folder from home (/Users/ruchi/) and used awk to get the folder name from a file name.

#for example let's say $1 has /Users/ruchi/Movies/Snowboarding 2010/videofile1.AVI
foldername=`echo "$1" | awk -F/ '{print $5}'` # That's right, not $4 but $5 due to leading "/"
echo $foldername #output: Snowboarding 2010

Here's another tutorial on how to pass variables to shell script.

Friday, February 4, 2011

Text Wrapping is Working

Many thanks to cimg's tutorial on dynamic cell height, text wrapping is working. If you want to keep the default font and size for the not-so-long data cells, keep the height fixed as 44.0f and use "initWithStyle:UITableViewCellStyleDefault" formatting on those cells.

Thursday, February 3, 2011

iOS or Cocoa - lookup that method

I was feeling lost with what the parameters for a method and found the way to look it up without leaving xcode. Just CMD+double click the method.

Here's the link to thank for.
CGRectMake parameters ? « cocos2d for iPhone

And am writing this post using blogger bookmarklet (chrome addon) called "blog this". It lets you blog any webpage from that page.