• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ScriptingAddition for camelcase
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ScriptingAddition for camelcase


  • Subject: Re: ScriptingAddition for camelcase
  • From: Ronald Hofmann <email@hidden>
  • Date: Tue, 17 Jan 2012 03:51:00 +0100

Hi Tom,
this is great, I´ll give it a try.

I also have a ASLib with functions I´m using every now and than and I´ve done this uppercase and lowercase thingy like this:

on changeCase(theText, action)


if action = "hi" then
set cmd to "echo " & quoted form of theText & " | tr \"[:lower:]\" \"[:upper:]\""
else if action = "lo" then
set cmd to "echo " & quoted form of theText & " | tr \"[:upper:]\" \"[:lower:]\""
else if action = "hilo" then
(*  not solved yet   
set cmd to "echo " & quoted form of theText & " \"[@]^\""
*)
end if


return (do shell script cmd)


end changeCase

Ronald
---


Am 17.01.2012 um 03:43 schrieb BareFeetWare:

Hi Ronald,

In reply to your email:

does anyone know of a ScriptingAddition which does camelcase?

Examplae: camelcase "this example please" -> "This Example Please" 

I´m using Satimage but this only contains lowercase and uppercase :(

You don't need a scripting addition. Just a simple script like this:

on CamelCase(oldText)
set camelList to {} & LowerCase(first word in oldText)
repeat with thisWord in the rest of the words in oldText
set end in camelList to UpperCase(first character in thisWord)
set remainingText to (rest of characters in thisWord as text)
if remainingText is not "" then
set end in camelList to LowerCase(remainingText)
end if
end repeat
set camelText to camelList as text
return camelText
end CamelCase

Use it like this:

CamelCase("this example please")

which gives:

thisExamplePlease

You can use the LowerCase and UpperCase from your scripting addition, or write those as a script too. Here's what I use (well, used to use) below.

property lowerChars : "abcdefghijklmnopqrstuvwxyz"
property upperChars : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

on run
return CamelCase("this is a test")
end run

on ListToText of theList between delimiter
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set joinedText to theList as text
set AppleScript's text item delimiters to oldDelims
return joinedText
end ListToText

on ReplaceEach of oldText by newChars instead of oldChars
set newList to {}
repeat with characterN from 1 to length of oldText
set oldCharacter to (character characterN in oldText) as text
set alphaN to (offset of oldCharacter in oldChars)
if alphaN > 0 then
set end of newList to character alphaN of newChars
else
set end of newList to oldCharacter
end if
end repeat
return ListToText of newList between ""
end ReplaceEach

on UpperCase(oldText)
return (ReplaceEach of oldText by upperChars instead of lowerChars)
end UpperCase

on LowerCase(oldText)
return (ReplaceEach of oldText by lowerChars instead of upperChars)
end LowerCase

Tom
BareFeetWare

--
iPhone/iPad/iPod and Mac software development, specialising in databases
email@hidden
--
Twitter: http://twitter.com/barefeetware/
Facebook: http://www.facebook.com/BareFeetWare


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: ScriptingAddition for camelcase (solved)
      • From: Ronald Hofmann <email@hidden>
References: 
 >ScriptingAddition for camelcase (From: Ronald Hofmann <email@hidden>)
 >Re: ScriptingAddition for camelcase (From: BareFeetWare <email@hidden>)

  • Prev by Date: Re: ScriptingAddition for camelcase
  • Next by Date: Re: ScriptingAddition for camelcase (solved via PHP)
  • Previous by thread: Re: ScriptingAddition for camelcase
  • Next by thread: Re: ScriptingAddition for camelcase (solved)
  • Index(es):
    • Date
    • Thread