calebmouse wrote:
Thanks for the assist Badunit!
What I want to know now:
Can I insert an AppleScript button into my Numbers document? I assume I use the inspector to make a button in Numbers to activate an AppleScript, how?
NO
You just may install a script like this one in the Script Menu.
--
--[SCRIPT triggerSeveralBoxes]
(*
Enregistrer le script en tant que Script, Application ou Progiciel : triggerSeveralBoxes.xxx
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
cliquer dans la cellule 'Enable Preset Group x'
menu Scripts > Numbers > triggerSeveralBoxes
Le script bascule l'état de la case à cocher adjacente
et fixe l'état des cases du groupe correspondant.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
+++++++
Save the script as Script, Application or Application Bundle: triggerSeveralBoxes.xxx
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Click in the cell 'Enable Preset Group x'
menu Scripts > Numbers > triggerSeveralBoxes
The script switches the status of the adjacent checkbox
and set accordingly the sttus of boxes of the corresponding group.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
--=====
Yvan KOENIG (Vallauris, FRANCE)
1 juillet 2009
*)
--=====
-- Set these four properties to fit your needs
property docName : "myDoc.numbers"
property sheetName : "Feuille 1"
property masterName : "Tableau 2"
property targetName : "Tableau 1"
on run
set {dName, sName, tName, rName, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
if dName is not docName then
if my parleAnglais() then
error "This is not the document “" & docName & "” !"
else
error "Ce n’est pas le document « " & docName & " » !"
end if
end if
if sName is not sheetName then
if my parleAnglais() then
error "This is not the sheet “" & sheetName & "” in the document “" & docName & "” !"
else
error "Ce n’est pas la feuille « " & sheetName & " » du document « " & docName & " » !"
end if
end if
if tName is not masterName then
if my parleAnglais() then
error "This is not the table “" & masterName & "” in the sheet “" & sheetName & "” in the document “" & docName & "” !"
else
error "Ce n’est pas la table « " & masterName & " » de la feuille « " & sheetName & " » du document « " & docName & " » !"
end if
end if
tell application "Numbers" to tell document docName to tell sheet sheetName
if not (exists table targetName) then
if my parleAnglais() then
error "The table “" & targetName & "” in the sheet “" & sheetName & "” in the document “" & docName & "” is unavailable !"
else
error "La table « " & targetName & " » de la feuille « " & sheetName & " » du document « " & docName & " » n’existe pas !"
end if
end if -- not exists …
if colNum1 is not 1 then
if my parleAnglais() then
error "The cursor is out of range !"
else
error "Le curseur est hors zone sensible !"
end if
end if
tell table masterName to tell column (colNum1 + 1)
set vv to not (value of cell rowNum1)
clear cell rowNum1
set value of cell rowNum1 to vv
set format of cell rowNum1 to checkbox
end tell
if rowNum1 = (2 + 1) then -- set values of cells of group 1)
my triggerTarget({1, 4}, vv) (* adjust the list to fit your needs *)
else if rowNum1 = (2 + 2) then -- set values of cells of group 2)
my triggerTarget({2, 3, 5, 7}, vv) (* adjust the list to fit your needs *)
else if rowNum1 = (2 + 3) then -- set values of cells of group 3)
my triggerTarget({6, 9}, vv) (* adjust the list to fit your needs *)
else if rowNum1 = (2 + 4) then -- set values of cells of group 4)
my triggerTarget({8, 10, 11}, vv) (* adjust the list to fit your needs *)
else
if my parleAnglais() then
error "The cursor was out of range !"
else
error "Le curseur est hors zone sensible !"
end if
end if
end tell
end run
--=====
on triggerTarget(group, v)
tell application "Numbers" to tell document docName to tell sheet sheetName to tell table targetName
repeat with g in group
set r to 1 + g
tell column 2
clear cell r
set value of cell r to v
set format of cell r to checkbox
end tell
tell column 3
clear cell r
set value of cell r to v (* maybe you will set it to (not v) *)
set format of cell r to checkbox
end tell
end repeat
end tell
end triggerTarget
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if
set two_Names to my decoupe(r_Name, ":")
set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
if item 2 of two_Names = item 1 of two_Names then
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
else
set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
end if
return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
end getSelParams
--=====
(*
set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
apply to named row or named column !
*)
on decipher(n, d, s, t)
tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
end decipher
--=====
(*
set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theDoc, theSheet, theTable, theRange}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
--
Yvan KOENIG (from FRANCE mardi 14 juillet 2009 21:05:40)