• 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 (solved via PHP)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ScriptingAddition for camelcase (solved via PHP)


  • Subject: Re: ScriptingAddition for camelcase (solved via PHP)
  • From: Alex Zavatone <email@hidden>
  • Date: Mon, 16 Jan 2012 22:16:37 -0600

What do you do after those 2 lines to make this happen?

On Jan 16, 2012, at 10:04 PM, Ronald Hofmann wrote:

Hi all,
I found a short PHP solution which does the job :)

set theText to "Many thanks for your feedback"
set myCmd to "PHP -r 'echo ucwords(strtolower(\"" & theText & "\n\"));'"

Greetings 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

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:
    • Fwd: ScriptingAddition for camelcase (solved via PHP)
      • From: Brian Christmas <email@hidden>
References: 
 >ScriptingAddition for camelcase (From: Ronald Hofmann <email@hidden>)
 >Re: ScriptingAddition for camelcase (From: BareFeetWare <email@hidden>)
 >Re: ScriptingAddition for camelcase (solved via PHP) (From: Ronald Hofmann <email@hidden>)

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