TextCommands issue with possessive words

set theString to "the moriarty's"

tell application "TextCommands"
set theString to titlecase theString
return theString

returns – “The Moriarty’S”

Clearly, I don’t want the " 's " capitalized. Does anyone know a way around this issue?

I see reference to Satimage being able to handle this. But, the dictionary does not appear to support titlecase, only upper and lower.

Any help would be appreciated.

Try this

set theString to "the moriarty's"
do shell script "/bin/echo " & quoted form of theString & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1'"

That seems to be perfect.


Of course, the tail end of that shell script means nothing to me, unfortunately. I guess I have some more reading to do…

Reviving an old thread here.

Anyone know how I could revise this to also account for “Mc” names & hyphenated terms?

So “McDonald’s” would not return “Mcdonald’s.” And, “Smith-Nelson” wouldn’t return “Smith-nelson.”

I’m a lazy bastard,
So I’d set Mc as text item delimiters after the first processing of a name, if I then got two items, I’d pass the first one through again. Recrate the new text with the text item delimiter, then I’d set the text item delimiter to “-”, and pass it through again, and revive it once again.

Then, if the name was mcgregor-olson originally, then it would turn out as McGregor-Olson.

It is a bite expensive, but I think Satimage.Osax has title case nowadays.

Here is a piece I made for you, using sed, but only when it has to, that you can rework to suit your needs.

This will only work well on Snow Leopard and newer.

set a to {"O'reilly", "mcgregor", "smith-tønnesen"}
repeat with aname in a
	local workMaterial, toUp, uppered
	set workMaterial to contents of aname as text
	set toUp to text 1 of workMaterial # grabs the character to uppercase.
	set uppered to titleCase for toUp
	set workMaterial to uppered & text 2 thru -1 of workMaterial
	# The initial first letter should now be uppercase.
	repeat with aDelim in {"O'", "Mc", "-"}
		local tids, namPieces
		set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, contents of aDelim}
		set namPieces to text items of workMaterial
		if (length of namPieces) > 1 then # One of the delimiters present.
			set toUp to text 1 of item 2 of namPieces # uppercase the piece.
			set uppered to titleCase for toUp
			set text item 2 of namPieces to uppered & text 2 thru -1 of text item 2 of namPieces
			set workMaterial to namPieces as text # put the fixed name back.
			set AppleScript's text item delimiters to tids
		end if
	end repeat
	set contents of aname to workMaterial # set the fixed name back into the list.
end repeat
log a
to titleCase for aCh
	local titleChar
	set titleChar to (do shell script "sed -e ' y/abcdefghijklmnopqrstuvwxyzæøå/ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ/' <<<" & aCh)
	return titleChar
end titleCase