• 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: Script Starter Templates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Starter Templates


  • Subject: Re: Script Starter Templates
  • From: Shane Stanley <email@hidden>
  • Date: Thu, 24 Dec 2015 10:06:06 +1100

On 24 Dec 2015, at 7:06 AM, Yvan KOENIG <email@hidden> wrote:

(1) Your camelCase handler maybe fine for English users - although I dislike the fact that it use the deprecated ASCII number.
For non English users, it fail to convert the accented chars.

I fear you're missing what Steve means by camelCase. He means as generally used for variable names in programming, so "un éléphant ça trompe" would become "unÉléphantÇaTrompe". However, in this case I suspect accents would be out; they are usually not allowed in variable names in programming languages.

You're right that he should use id rather than ASCII number, but he's on 10.6 so ASObjC is out. But for ASObjC users there's a method that capitalizes just the first character of words: capitalizedString. So if here were on 10.9 or later, he could use:

on camelCase(aPhrase)
set firstWord to current application's NSString's stringWithString:(word 1 of aPhrase)
set firstWord to firstWord's |lowercaseString|() as text
set restOfPhrase to current application's NSString's stringWithString:(text from word 2 to -1 of aPhrase)
set restOfPhrase to (restOfPhrase's |capitalizedString|()'s stringByReplacingOccurrencesOfString:space withString:"") as text
return firstWord & restOfPhrase
end camelCase

However, non-English-speaking users might still need to watch out for éléphants, to remove the accents. I suspect that to do that in simple AppleScript would mean building a list of the ids of accented characters, and their equivalents. But if you wanted a foolproof ASObjC handler that also did that, it would be:

on camelCase(aPhrase)
set firstWord to current application's NSString's stringWithString:(word 1 of aPhrase)
set firstWord to firstWord's |lowercaseString|()
set restOfPhrase to current application's NSString's stringWithString:(text from word 2 to -1 of aPhrase)
set restOfPhrase to restOfPhrase's capitalizedString()'s stringByReplacingOccurrencesOfString:space withString:""
set newPhrase to firstWord's stringByAppendingString:restOfPhrase
return (newPhrase's stringByFoldingWithOptions:(current application's NSDiacriticInsensitiveSearch) locale:(missing value)) as text
end camelCase

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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: Script Starter Templates
      • From: Yvan KOENIG <email@hidden>
References: 
 >Script Starter Templates (From: "S. J. Cunningham" <email@hidden>)
 >Re: Script Starter Templates (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 12, Issue 643
  • Next by Date: Re: Scriptable applications
  • Previous by thread: Re: Script Starter Templates
  • Next by thread: Re: Script Starter Templates
  • Index(es):
    • Date
    • Thread