I am tired but it's done.
--
--[SCRIPT]
(*
Enregistrer le script en tant que Script : create3docs.scpt
déplacer l'application créée 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.
Ouvrez le document Numbers à découper: folderName stocké sur le bureau.
Sélectionner le bloc de cellules à séparer.
menu Scripts > Numbers > create3docs
Le script crée les trois fichiers souhaités dans un dossier du dossier Documents.
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 a Script: create3docs.scpt
Move the newly created application 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.
Open the Numbers document named foldername (on the Desktop).
menu Scripts > Numbers > create3docs (run the script)
The script creates the three wanted files in a folder of the documebts folder..
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)
2009/11/03
*)
--=====
property listeBall : {}
property listeBlock : {}
property listeBrick : {}
property ListeX : {}
property mainFolder : ""
property folderName : "BallBlockBrick"
--=====
on run
my nettoie()
my activateGUIscripting()
set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
repeat with r from rowNum1 to rowNum2
tell row r
set maybe to (value of cell (colNum1)) as text
set couleur to {(value of cell (colNum1 + 1))}
set prix to {(value of cell (colNum1 + 2))}
--considering case
if maybe is "ball" then
copy {couleur, prix} to end of my listeBall
else if maybe is "block" then
copy {couleur, prix} to end of my listeBlock
else if maybe is "brick" then
copy {couleur, prix} to end of my listeBrick
else
--
end if -- maybe…
--end considering
end tell -- row…
end repeat -- with r…
end tell -- "Number"
copy my listeBall to my ListeX
my treatAtype("Ball.numbers")
copy my listeBlock to my ListeX
my treatAtype("Block.numbers")
copy my listeBrick to my ListeX
my treatAtype("Brick.numbers")
my nettoie()
end run
--=====
on treatAtype(fileName)
local pathX
log my ListeX
set p2d to path to documents folder as text
set mainFolder to (p2d & folderName & ":")
tell application "System Events"
if not (exists folder mainFolder) then make new folder at end of folder p2d with properties {name:fileName}
if not (exists disk item (mainFolder & fileName)) then
set needNew to true
else
set needNew to false
end if
end tell -- "System Events"
if needNew then
set pathX to (my makeNewDoc(fileName, mainFolder)) as text
else
set pathX to (mainFolder & fileName) as alias
tell application "Numbers" to open pathX
end if
tell application "Numbers"
tell document fileName to tell sheet 1 to tell table 1
repeat with r from 2 to row count
if value of cell r of column 2 is 0.0 then exit repeat
end repeat
(* here r is index of first blank row *)
if not r < row count then
add row below last row
set r to r + 1
end if -- r…
repeat with i from 1 to count of my ListeX
if r = row count then
add row below last row
end if
tell row r
set value of cell 2 to (item 1 of (item i of my ListeX)) as text
set value of cell 3 to (item 2 of (item i of my ListeX)) as real
end tell
set r to r + 1
end repeat -- with i…
end tell -- shell & table
save document fileName
close document fileName
end tell -- Numbers
end treatAtype
--=====
(*
set { dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
*)
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
--=====
on nettoie()
set my listeBall to {}
set my listeBlock to {}
set my listeBrick to {}
set my ListeX to {}
set mainFolder to ""
end nettoie
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
on makeNewDoc(n, d)
local f, t
set f to d & n
set t to ((path to applications folder as text) & "iWork '09:Numbers.app:Contents:Resources:Templates:Blank.nmbtemplate:") as alias
tell application "Numbers"
open t
save document 1 as n in file f
end tell -- Numbers
return d as alias
end makeNewDoc
--=====
--[SCRIPT]
--
Yvan KOENIG (VALLAURIS, France) mardi 3 novembre 2009 22:49:46