Can Automator work with Numbers?

I have a numbers sheet that is a long list items.

COLUMN1 COLUMN2 COLUMN3
ball red $10
block red $3
brick yellow $4
ball yellow $10
block yellow $3

I would like to write a macro that splits and saves this file into 3 separate files (balls, blocks, and bricks). Is this something I can use Automator for?

Thanks in advance

Dual G5 Leopard Server, Dual quad core Mac Pro, Macbook Pro, Mac OS X (10.6.1)

Posted on Oct 28, 2009 8:52 AM

Reply
11 replies

Oct 29, 2009 1:29 PM in response to krw

krw,

While you are considering the Script option you can get by with Sorting on what you call Column 1. Select all the rows containing, for instance, Ball, and then drag that block to a blank area on the canvas. Now you will have created a table containing only the desired object type.

Open a new Numbers Document. Right-Click the separated data's table name in the original document and select Copy. Then Right-Click the Sheet Pane of the new document and select Paste.

You will now have a new document with a copy of your data pertaining to the particular object you selected.

This all takes longer to say than to do.

Jerry

Nov 2, 2009 4:56 AM in response to KOENIG Yvan

Thanks for being willing to take the time Yvan. If you would post what ever you have as a start, I'd like to see if I could use it to get me started. I've never used applescript, I do my scripting with withe sh or perl. However, I am trying to help out a colleague who is not a programmer, not command line oriented and will only use this on a her Mac with Numbers, hence my first idea to ask about automator. However, if you thing applescript is the way to go, it might be a good excuse for me to learn a little bit about applescript.

Nov 3, 2009 1:49 PM in response to KOENIG Yvan

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

Nov 4, 2009 10:44 AM in response to krw

Thanks for the feedback.
Just a bit of knowledge upon AppleScript and Numbers.

It was long to achieve
because:
(1) We are making changes in our house
(2) I am suffering of my eyes even these last days when I was just a short time in front of my mac.

What was the more annoying was to find a typo which was not generating an error message.
I had to put a lot of log instructions to 'trace' the script behavior and with 'bad eyes', ,it was really painful.

But the important is that now you have the wanted tool.

When my eyes will be in better state I will try to enhance the beast so that it will no longer fixed to three extracted files.

Yvan KOENIG (VALLAURIS, France) mercredi 4 novembre 2009 19:44:19

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can Automator work with Numbers?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.