I wished that they add a « select sheet « or « bring to front sheet » so that cumbersome code would no longer be required when I have to use GUI scripting to replace missing features like « fill down », « fill to right »
These are really interesting when we have to build a table with formulas.
Building a formula is cumbersome because it must match the localization setting so building it only once and apply Fill down is really useful.
For those which may be interested here are two simple sample scripts which I use often (in their 2.x version of course) and updated yesterdays.
# <SCRIPT>
# localized formulas in Numbers 3.1
# Yvan KOENIG (VALLAURIS, France)
# 2014/01/24
tell application "Numbers"
set IF_loc to localized string "IF" from table "TSCalculationEngine"
set ISBLANK_loc to localized string "ISBLANK" from table "TSCalculationEngine"
set ROUND_loc to localized string "ROUND" from table "TSCalculationEngine"
set SUMSQ_loc to localized string "SUMSQ" from table "TSCalculationEngine"
end tell
if character 2 of (1 / 2 as text) is "." then
set deci_loc to "."
set separator_loc to ","
else
set deci_loc to ","
set separator_loc to ";"
end if
log {IF_loc, ISBLANK_loc, ROUND_loc, deci_loc, separator_loc}
(*SI, ESTVIDE, ARRONDI, ,, ;*)
# localize =IF(ISBLANK(C19),"",IF(C19,C19,""))
set formula_loc1 to "=" & IF_loc & "(" & ISBLANK_loc & "(C19)" & separator_loc & quote & quote & separator_loc & IF_loc & "(C19" & separator_loc & "C19" & separator_loc & quote & quote & "))"
--> "=SI(ESTVIDE(C19);\"\";SI(C19;C19;\"\"))"
# localize =ROUND(1.2345,2)
set formula_loc2 to "=" & ROUND_loc & "(1" & deci_loc & "2345" & separator_loc & "2)"
--> "=ARRONDI(1,2345;2)"
# localize =SUMSQ(2,3,4)
set formula_loc3 to "=" & SUMSQ_loc & "(2" & separator_loc & "3" & separator_loc & "4)"
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
set value of cell "B3" to formula_loc1
set value of cell "B10" to formula_loc2
set value of cell "C19" to formula_loc3
end tell
# </SCRIPT>
# <SCRIPT>
# localized month names and day names in Numbers 3.1
# Yvan KOENIG (VALLAURIS, France)
# 2014/01/24
set English_Months to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
tell application "System Events"
set p2Numbers to file of process "Numbers" as text
end tell
set p2resourceMonths to (p2Numbers & "Contents:SharedSupport:Templates:07_Calendar") as alias
tell application "Numbers"
set January_loc to localized string "January" in bundle p2resourceMonths
--> "Janvier"
set February_loc to localized string "February" in bundle p2resourceMonths
--> "Février"
set March_loc to localized string "March" in bundle p2resourceMonths
--> "Mars"
set April_loc to localized string "April" in bundle p2resourceMonths
--> "Avril"
set May_loc to localized string "May" in bundle p2resourceMonths
--> "Mai"
set June_loc to localized string "June" in bundle p2resourceMonths
--> "Juin"
set July_loc to localized string "July" in bundle p2resourceMonths
--> "Juillet"
set August_loc to localized string "August" in bundle p2resourceMonths
--> "Août"
set September_loc to localized string "September" in bundle p2resourceMonths
--> "Septembre"
set October_loc to localized string "October" in bundle p2resourceMonths
--> "Octobre"
set November_loc to localized string "November" in bundle p2resourceMonths
--> "Novembre"
set December_loc to localized string "December" in bundle p2resourceMonths
--> "Décembre"
set Monday_loc to localized string "Monday" in bundle p2resourceMonths
--> "Lundi"
set Tuesday_loc to localized string "Tuesday" in bundle p2resourceMonths
--> "Mardi"
set Wednesday_loc to localized string "Wednesday" in bundle p2resourceMonths
--> "Mercredi"
set Thursday_loc to localized string "Thursday" in bundle p2resourceMonths
--> "Jeudi"
set Friday_loc to localized string "Friday" in bundle p2resourceMonths
--> "Vendredi"
set Saturday_loc to localized string "Saturday" in bundle p2resourceMonths
--> "Samedi"
set Sunday_loc to localized string "Sunday" in bundle p2resourceMonths
--> "Dimanche"
end tell
# CAUTION : if the language is French, to write dates we must convert the strings to lowercase.
# I’m sure that hard coding the French strings would be more efficient
if Sunday_loc is "Dimanche" then
set January_loc to my lower_case(January_loc)
--> "janvier"
set February_loc to my lower_case(February_loc)
--> "février"
set March_loc to my lower_case(March_loc)
--> "mars"
set April_loc to my lower_case(April_loc)
--> "avril"
set May_loc to my lower_case(May_loc)
--> "mai"
set June_loc to my lower_case(June_loc)
--> "juin"
set July_loc to my lower_case(July_loc)
--> "juillet"
set August_loc to my lower_case(August_loc)
--> "août"
set September_loc to my lower_case(September_loc)
--> "septembre"
set October_loc to my lower_case(October_loc)
--> "octobre"
set November_loc to my lower_case(November_loc)
--> "novembre"
set December_loc to my lower_case(December_loc)
--> "décembre"
set Monday_loc to my lower_case(Monday_loc)
--> "lundi"
set Tuesday_loc to my lower_case(Tuesday_loc)
--> "mardi"
set Wednesday_loc to my lower_case(Wednesday_loc)
--> "mercredi"
set Thursday_loc to my lower_case(Thursday_loc)
--> "jeudi"
set Friday_loc to my lower_case(Friday_loc)
--> "vendredi"
set Saturday_loc to my lower_case(Saturday_loc)
--> "samedi"
set Sunday_loc to my lower_case(Sunday_loc)
--> "dimanche"
end if
on lower_case(txt)
tell application "ASObjC Runner"
return modify string txt so it is lower
end tell
end lower_case
# </SCRIPT>