Blog headline image

Tag Archives: pages

Title Case in Pages

September 4th, 2013 by ‐ No Comments

If you are using Pages as your text document creator (note we didn’t say “word processor”), you have probably bounced your head against some of its limitations (e.g. no auto-numbering of figures and tables, no auto-insertion of bookmark text when creating cross references). One of the things that can be fixed relatively easily, is the lack of a text transformation to adjust upper/lower case to Title Case as needed for headings. To achieve this, just use this little shell script, and wrap it into an automator service that receives the selected text from Pages.

lowerwords=$(echo -n $* | tr '[[:upper:]]' '[[:lower:]]')
numwords=$(echo -n $* | wc -w) # in Automator $# is always 1
wordcount=0
for word in $lowerwords ; do
   wordcount=$(( $wordcount + 1 ))
   if [ $wordcount -gt 1 -a $wordcount -lt $numwords ] ; then
      case $word in
         a|an|the|and|but|or|for|nor|in|on|of|upon|to|as|at|by) echo -n "$word "; continue; ;;
      esac
   fi
   firstletter=$(echo -n $word | cut -c1 | tr '[[:lower:]]' '[[:upper:]]')
   otherletters=$(echo -n $word | cut -c2-)
   echo -n "$firstletter$otherletters"
   if [ $wordcount -lt $numwords ] ; then
      echo -n " "
   fi
done

Of course this is easily adapted to convert to all lower and all upper case, and can also be saved as an Automator service under a calling name.