• 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: Yvan KOENIG <email@hidden>
  • Date: Thu, 24 Dec 2015 10:13:57 +0100


Le 2015/12/24 à 00:06, Shane Stanley <email@hidden> a écrit :

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


Thanks Shane. 


(1) I'm an ass but the help is too.
When I searched in the Xcode help, I searched for "lowercaseString"
I got it and scrolled to the bottom.
So I got references to
lowercaseStringWithLocale:
uppercaseString
uppercaseStringWithLocale:
but nothing about capitalizeString which-logically - is available before lowerCaseString.
Why isn't it referenced in the numerous "See Also" blocks of datas, I don't know.

(2) About accented characters, you are right if you write about variable names, minus the fact that we may use them if we enclose the name with vertical bars.
You are right upon the fact that I missed the fact that Steve concatenated the words of the source phrase without the original spaces I see no evidence that he was building variable names. In such case I see no reason to drop non ASCII characters.

(3) As Steve used them, using words to split the phrase in - words - was my first idea but I remembered that word doesn't mean the same thing everywhere. This is why I choose to split with the space delimiter.
Maybe it wasn't a good choice but at least it highlighted the fact that a variable remained with its "old" name breaking the handler getTextItems .

Given all that, I will store three versions of camelCase so that I have one available for each situation.


Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) jeudi 24 décembre 2015 10:13:51


 _______________________________________________
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

References: 
 >Script Starter Templates (From: "S. J. Cunningham" <email@hidden>)
 >Re: Script Starter Templates (From: Yvan KOENIG <email@hidden>)
 >Re: Script Starter Templates (From: Shane Stanley <email@hidden>)

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