Maybe you will find what you need in :
(*
Pages 5.0 casses
Yvan KOENIG (VALLAURIS, France)
*)
# Initialisation de quelques variables
if my parle_anglais() then
set lesChoix_theChoices to {"lowercase", "UPPERCASE", "Sentences"}
set leTitre_theTitle to "Select a case"
set errMessage to "Nothing is selected in Pages !"
else
set lesChoix_theChoices to {"minuscules", "MAJUSCULES", "Phrase"}
set leTitre_theTitle to "Casse à appliquer"
set errMessage to "Rien n'est sélectionné dans Pages !"
end if
# Use the Finder's localized strings so that default shortcut escape apply
tell application "Finder"
set OKbtn to localized string "AL4"
set annuler_cancel to localized string "AL1"
end tell
tell application "/Applications/Pages.app" to activate
tell application "System Events" to tell (first process whose frontmost is true)
set appID to its id
end tell
(*
Fill the clipboard with a fake string *)
set tt to "All The Things You Could Be By Now If Sigmund Freud's Wife Was Your Mother, © Charles Mingus"
set the clipboard to tt
tell application "System Events" to tell (first process whose id is appID)
delay 0.2
keystroke "c" using {command down}
tell (first application whose frontmost is true)
(*
Loop waiting the achievement of the Copy task. *)
repeat 30 times
try
if (the clipboard as text) is not tt then exit repeat
on error
delay 0.1
end try
end repeat
set texte_text to the clipboard as text
if texte_text is tt then error errMessage
tell application "/Applications/Pages.app" # (path to frontmost application as string) to put the dialog at front
set quelleCasse_whichCase to choose from list lesChoix_theChoices with title leTitre_theTitle OK button name OKbtn cancel button name annuler_cancel
if quelleCasse_whichCase is false then error number -128
set quelleCasse_whichCase to item 1 of quelleCasse_whichCase
end tell
if quelleCasse_whichCase = item 3 of lesChoix_theChoices then
repeat with eol in {".", "!", "?", "."}
set liste_list to my decoupe(texte_text, eol as text)
repeat with i from 1 to count liste_list
set item_i to item i of liste_list
set |trouvéDébutDePhrase_foundBegOfSentence| to false
repeat with j from 1 to count item_i
if (character j of item_i) is not in {space, tab, linefeed, return, character id 8232, character id 8233} then
set |trouvéDébutDePhrase_foundBegOfSentence| to true
exit repeat
end if
end repeat # j
if |trouvéDébutDePhrase_foundBegOfSentence| then
character j of item_i
set converti_converted to my changecase(result, "upper")
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
set l to text items of item_i
set item j of l to converti_converted
set item_i to l as text
set AppleScript's text item delimiters to oTIDs
end if
set item i of liste_list to item_i
end repeat # i
set texte_text to my recolle(liste_list, eol as text)
end repeat # eol
else if quelleCasse_whichCase is item 1 of lesChoix_theChoices then
set texte_text to my changecase(texte_text, "lower")
else if quelleCasse_whichCase is item 2 of lesChoix_theChoices then
set texte_text to my changecase(texte_text, "upper")
end if
set the clipboard to texte_text
end tell
keystroke "v" using {command down}
end tell
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to "" & l
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(*
Le second argument peut être: "upper", "lower", "title", "capitalize"
ATTENTION, capitalize change uniquement le premier caractère de la sélection
*)
on changecase(txt, mode)
set python_script to "import sys; print sys.argv[1].decode('utf8')." & mode & "().encode('utf8')"
return do shell script "/usr/bin/python -c " & quoted form of python_script & " " & quoted form of txt
end changecase
#=====
(*
Le second argument peut être: "upper", "lower", "capitalize"
ATTENTION, capitalize change uniquement le premier caractère de la sélection
*)
(*
on change_case(txt, mode)
tell application "ASObjC Runner"
if mode is "upper" then
return modify string txt so it is caps
else if mode is "lower" then
return modify string txt so it is lower
else if mode is "capitalize" then
return modify string txt so it is cap words
end if
end tell
end change_case
*)
#=====
on parle_anglais()
return (do shell script "defaults read 'Apple Global Domain' AppleLocale") does not start with "fr_"
end parle_anglais
#=====
The script was written for a French user so several varNames and handlerNames are ” more or less ” French Words.
Yvan KOENIG (VALLAURIS, France) vendredi 17 janvier 2014 17:28:41