Here is my script.
I know that some users dislike GUI scripting but with Numbers it’s the best way to keep every attributes/formats of datas.
As it extracts and insert the entire sets of datas in a single operation it’s the fastest responce.
--{code}
--[SCRIPT from_listings_to_weekly]
(*
Enregistrer le script en tant que Script : from_listings_to_weekly.scpt
déplacer le fichier ainsi 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.
Ouvrir les fichiers Listings.numbers et Weekly Listings.numbers
Aller au menu Scripts , choisir Numbers puis choisir "from_listings_to_weekly"
Le script remplit les fiches du fichier Weekly Listings.numbers
--=====
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".
Sous 10.6.x,
aller dans le panneau "Général" du dialogue Préférences de l'Éditeur Applescript
puis cocher la case "Afficher le menu des scripts dans la barre des menus".
--=====
Save the script as a Script: from_listings_to_weekly.scpt
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.
Open the files Listings.numbers and Weekly Listings.numbers
Go to the Scripts Menu, choose Numbers, then choose "from_listings_to_weekly"
The script fill the records in the file Weekly Listings.numbers
--=====
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.
Under 10.6.x,
go to the General panel of AppleScript Editor's Preferences dialog box
and check the "Show Script menu in menu bar" option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/08/20
*)
--=====
on run
local document_source, document_cible, ouvert1, ouvert2, attention, extraits
set document_source to "Listings.numbers"
set document_cible to "Weekly Listings.numbers"
(*
Check that the wanted documents are open *)
tell application "Numbers"
set ouvert1 to exists document document_source
set ouvert2 to exists document document_cible
end tell
set attention to {}
if my parleAnglais() then
if not ouvert1 then copy "The document "" & document_source & "" is not open !" to end of attention
if not ouvert2 then copy "The document "" & document_cible & "" is not open !" to end of attention
else
if not ouvert1 then copy "Le document « " & document_source & " » n'est pas ouvert !" to end of attention
if not ouvert2 then copy "Le document « " & document_cible & " » n'est pas ouvert !" to end of attention
end if
if attention is not {} then error my recolle(attention, return)
my activateGUIscripting()
(*
Put document_source at front *)
my selectMenu("Numbers", 10, document_source)
(*
Select every cells of table 1 of sheet 1 starting from cell A2 *)
tell application "Numbers" to tell document document_source to tell sheet 1 to tell table 1
set selection range to range ("A2 : " & name of last cell)
end tell
(*
Copy the selected cells *)
set source to my copyToClipboard("Numbers")
(*
Put document_cible at front *)
my selectMenu("Numbers", 10, document_cible)
(*
Extract the list of MLS thru Copy to Clipboard to keep them as 'strings'
Extracting them the standard way 'get value' would coerce them in scientific format *)
tell application "Numbers" to tell document document_cible to tell sheet 1 to tell table 1
set selection range to range ("A2 : " & name of last cell of column 1)
end tell
set des_MLS to paragraphs of my copyToClipboard("Numbers")
(*
Extract the datas linked to the MLSs
Edited on 2011/08/22 *)
set extraits to {}
repeat with un_MLS in des_MLS
try
copy paragraph 1 of item 2 of my decoupe(source, return & un_MLS & tab) to end of extraits
on error
copy tab to end of extraits
end try
end repeat
(*
Put these datas in the clipboard *)
set the clipboard to my recolle(extraits, return)
(*
Select the cell B2 which is the first cell to fill *)
tell application "Numbers" to tell document document_cible to tell sheet 1 to tell table 1
set selection range to range "B2"
end tell
(*
Paste matching style *)
my raccourci("Numbers", "v", "cas")
end run
--=====
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 decoupe(t, d)
local oTIDs, l
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to 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 to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
--=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
--=====
(*
==== Uses GUIscripting ====
*)
(*
This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.
I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.
*)
on raccourci(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end raccourci
--=====
(*
my selectMenu("Pages",5, 12)
==== Uses GUIscripting ====
*)
on selectMenu(theApp, mt, mi)
tell application theApp
activate
tell application "System Events" to tell process theApp to tell menu bar 1 to ¬
tell menu bar item mt to tell menu 1 to click menu item mi
end tell -- application theApp
end selectMenu
--=====
on copyToClipboard(theApp)
local contenu
set the clipboard to ""
(*
Copy the selection to the clipboard *)
my raccourci(theApp, "c", "c") (* Copy *)
(*
Wait for achievement of the copy process *)
repeat
try
set contenu to the clipboard as text
if contenu > "" then
exit repeat
else
error number 12345
end if
on error
delay 0.1
end try
end repeat
return contenu
end copyToClipboard
--=====
--[/SCRIPT]
--{code}
Yvan KOENIG (VALLAURIS, France) samedi 20 août 2011 13:36:52