Can Applescript Print a Table from a Numbers Spreadsheet?

Have spent some time over the last week or so with a lot of valuable help from this forum I have now been able to get the manipulation I wanted on my Numbers 9 spreadsheet using Applescript. I know I can do it manually but what I would like to do is to print the altered tables, is this possible using Applescript?

ElBeardo :expressionless:

Well. I was going to reply: “Yes. Of course. tell application “Numbers” to print front document” But even that doesn’t appear to work properly! I keep getting an error message telling me to set up a printer in System Preferences first!

The less desirable GUI solution does seem to work though:

-- This assumes you want to use the default print settings:
tell application "Numbers" to activate
tell application "System Events"
	keystroke "p" using {command down}
	keystroke return
end tell

Nigel

As always you have been a great help, the trouble is I keep assuming that what worked in Excel would work in Numbers. I didn’t realise that in Numbers you can’t print just a range from a table or just a table but it prints a complete sheet. After putting the table on to a new sheet and fiddling about with some print parameters your script worked perfectly I am very grateful for your help

ElBeardo :slight_smile:

Given what is available in the Numbers Applescript’s dictionary, we are supposed to be able to print with plain vanilla code.

print‚v : Print an object.
print alias : The file(s) or document(s) to be printed.
[print dialog boolean] : Should the application show the Print dialog?
[with properties print settings] : the print settings

print settings‚n
properties
copies (integer) : the number of copies of a document to be printed
collating (boolean) : Should printed copies be collated?
starting page (integer) : the first page of the document to be printed
ending page (integer) : the last page of the document to be printed
pages across (integer) : number of logical pages laid across a physical page
pages down (integer) : number of logical pages laid out down a physical page
requested print time (date) : the time at which the desktop printer should print the document
error handling (standard/detailed) : how errors are handled
fax number (text) : for fax number
target printer (text) : for target printer

Alas, was never able to use them.
Not specific to Numbers, I am unable to rule the print task with specific parameters (subset of pages) in Pages.app

Seems that there is a real flaw in this area.

Yvan KOENIG (VALLAURIS, France) dimanche 20 février 2011 12:57:17

Here is a quick and dirty script which may be helpful.


--{code}
--[SCRIPT print_a_table]
(*
Enregistrer le script en tant que Script ou Application : print_a_table.xxx
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.

Sélectionner une partie de table, une table ou même plusieurs tables.
Aller au menu Scripts , choisir Numbers puis choisir  print_a_table
Le script crée un nouveau document depuis le modèle Vide,
supprime la table créée par défaut et colle le contenu du presse-papiers.
Il envoie enfin la commande d'impression.

--=====

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 or an Application : print_a_table.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.

Select a subset of a table, a table or even several tables.
Go to the Scripts Menu, choose Numbers, then choose "print_a_table"
The script create a new document based on the Blank template,
remove the default table and paste the clipboard's contents.
At last, it issue the print command.

--=====

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/02/20
*)
--=====

property theApp : "Numbers"

on run
	run script do_your_duty
end run

script do_your_duty
	my activateGUIscripting()
	(*
Copy the selected items *)
	my raccourci(theApp, "c", "c") (* cmd + c *)
	(*
Create a new document based upon Blank.template *)
	set myNewDoc to my makeAnIworkDoc(theApp)
	(*
Delete the default table *)
	tell application "Numbers" to tell document 1 to tell sheet 1 to delete table 1
	
	my raccourci(theApp, "v", "c") (* cmd + v = Paste *)
	
	my raccourci(theApp, "p", "c") (* cmd + p = Print *)
	my raccourci(theApp, return, "") (* return = validate the Print command*)
	
end script

--=====
(*
Creates a new iWork document from the Blank template and returns its name.
example:
set myNewDoc to my makeAnIworkDoc(theApp)
 *)
on makeAnIworkDoc(the_app)
	local maybe, path_to_the_App, nb_doc, doc_name
	if the_app is "Pages" then
		tell application "Pages"
			set nb_doc to count of documents
			make new document with properties {template name:item 1 of templates}
		end tell
	else if the_app is "Numbers" then
		tell application "System Events" to set maybe to the_app is in title of every application process
		if not maybe then tell application theApp to activate
		tell application "System Events"
			set path_to_the_App to get application file of application process the_app
		end tell
		tell application "Numbers"
			set nb_doc to count of documents
			open ((path_to_the_App as text) & "Contents:Resources:Templates:Blank.nmbtemplate:")
		end tell
	else
		if my parleAnglais(theApp) then
			error "The application "" & the_app & "" is not accepted !"
		else
			error "l'application « " & the_app & " » n'est pas gérée !"
		end if
	end if
	
	tell application the_app
		repeat until (count of documents) > nb_doc
			delay 0.1
		end repeat
		set doc_name to name of document 1
	end tell -- the_App
	return doc_name
end makeAnIworkDoc

--=====

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 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

--=====
--[/SCRIPT]
--{code}

Yvan KOENIG (VALLAURIS, France) dimanche 20 février 2011 19:07:06

I have to admit that I am starting to get to grips with Applescript but I find I spend a lot of my time banging my head against the proverbial brick wall. I have spent the last few days trying to automate Nigel’s piece of script. I originally got this to work by manually copying the cells from table 1 of sheet 1 as a new table in Sheet 2, adjusting the print size and then using Nigel’s script. This worked perfectly.
I then decided I would automate this by writing some script to copy the relevant cells from Sheet 1 to Sheet 2. I soon worked out that to work with two sheets I had to perform Tell / End Tell when I changed sheets. My problem was it took about two days to realise that the reason I could not get this to work was that my “tell table 2 of sheet 2” should have read 'tell table 1 of sheet 2".
I still find this confusing the table I want to print is called Table 2. When I created Sheet 2 it created Table 1 which I then deleted. I then manually copied over the range of cells from sheet1 to sheet 2 which created Table 2. I then used this as the template for my script.
I assume that the “tell table 1 of sheet 2” is working on relative numbers and if for some reason I had created a sheet 3 but then deleted sheet 2, then “tell table 1 of sheet 2” would still apply. I, again, assume to avoid this confusion I should give names to the various Sheets and Tables is that correct?
Yvan thank you for your script I haven’t had time to study it properly yet but hopefully will get round to it in the next few days.
Again many thanks for all the help

ElBeardo :slight_smile:

A table named “Table 36” may perfectly be the only one available in a sheet.

So, in my own practice, I never use tell table 2 of sheet 3 in serious scripts.

Always use tell table “name_of_a_table” of sheet “name_of_a_sheet”.

Yvan KOENIG (VALLAURIS, France) mercredi 23 février 2011 11:44:40

Yes. It’s a bit confusing at first. :slight_smile:

The “Table 2” you see in Numbers is a default name which Numbers gives to the table when it creates it. These names are assigned in “numerical” order, even though previous tables may have been deleted. This is a common practice with many applications. Usually, the numbering is incremented from the time the application or document was opened.

The reference ‘table 2 of sheet 2’ is an “index reference” to the second existing table of the second existing sheet, whatever those may happen to be at the time. If the sheet has only one table, the reference will fail. If there’s only one table and it’s called “Table 2” in Numbers, you can use either this index reference.

table 1 of sheet 2

. or this name reference:

table “Table 2” of sheet 2 (or perhaps table “Table 2” of sheet “Sheet 2”)

Obviously you’re not likely to use these particular name references, since you have to predict what the default names will be. However, if you’ve named the sheet and table yourself, as you can in Numbers, it’s not bad practice to use a name reference containing those names.

I think I have got my script to do what I want, I will have to tidy it up as at the moment it is several separate routines just as I developed each section. I will in the final tidy up update my notes on what is happening and rename tables and sheets as you suggest.

Once again many thanks for the help

ElBeardo :slight_smile:

Trust an old ape, if you built several routines (handlers) keep this structure.

Maintaining a code built with such objects is easier than maintaining a long flow of code.

Yvan KOENIG (VALLAURIS, France) mercredi 23 février 2011 17:42:54

Hi Yvan

I know what you mean I have been programming on and off since the mid-60’s. The tidying up I am talking about is although I have made notes in my scripts, I find they need to be expanded. The notes I have currently are OK while what I am doing is fresh in my mind, but six months down the line I need something to jog the brain a bit more.

You may be able to help on the other piece of tidying up I was thinking about save me some time searching. What I wondered if it was possible to write a simple master script which would run all the other scripts something like this.

Run Script1
Marker (Start Again)
Run Script2
If then
Run Script3
Goto Marker (Start Again)
End If
Run Script4
Run Script5
etc

Sorry to impose

ElBeardo :slight_smile:

This kind of program is described in the first resource that we are supposed to study :

AppleScriptLanguageGuide

Searching in Google return a link to it as first answer.

As AppleScript doesn’t support goto, some changes are required.
If I made no error, this structure will do the trick.

Run script Script1
repeat while
Run script Script2
Run script Script3
end repeat
Run script Script2
Run script Script4
Run script Script5

Yvan KOENIG (VALLAURIS, France) jeudi 24 février 2011 23:05:31

Thanks for that Yvan I now been able to get it to work and I think that this means I can tidy up a lot more than I first anticipated

ElBeardo :slight_smile:

Just when I thought I had everything sorted I have hit another snag. I have amalgamated all my various scripts using the run command and everything seemed to be working perfectly until I started to print out. I have been using Nigel’s piece of script from the 19th Feb, sorry Yvan at this stage your script and my level of knowledge were incompatible.
The problem I have come across is that I now have 3 separate tables on three different sheets. When I run Nigel’s script whichever table is showing in Numbers is the one printed out, the “tell table of sheet” appears to be ignored. Over the last couple of days I have tried various ways to tell which table and sheet I want printing but without success. I am obviously missing something or is what I am trying to do impossible?

ElBeardo :frowning:

If I took time to write a script allowing you to copy a table from your document to another one in which it will be the unique one, it’s clearly because there is no way (at least at this time) to print a single table of a defined sheet thru AppleScript.

I really don’t understand what is complicated with my script.

It’s not guaranteed to be able to fit your needs because it assumes that the sheet embedding the table to print is at front.

If it’s not, you will have to bring it to front.
This requires a convoluted handler.
I wrote one with the help of Nigel Garvey.

I added it to the script embedded in my late message.

CAUTION :

I didn’t changed the explanations.
The script is designed for a document containing at least two sheets.
I named the first sheet but here the name is unused.
The second sheet is supposed to be named “my second sheet”
It’s supposedto embed a table named “Table_to_copy”.
It may embed other tables.

I assume that when we call the script, it’s a table of the first script which is at front.

The script call the handler SelectSheet which of course is designed to select the sheet named “my second sheet” in the document at front. This is why the handler is called with :

my selectSheet(1, sheet2)

In a more complicated script it would be useful to replace the parameter 1 by the name of the document.
When the sheet is selected, the script select every cells of the required table.
Then, we retrieve my original code.



--{code}
--[SCRIPT print_a_table]
(*
Enregistrer le script en tant que Script ou Application : print_a_table.xxx
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.

Sélectionner une partie de table, une table ou même plusieurs tables.
Aller au menu Scripts , choisir Numbers puis choisir print_a_table
Le script crée un nouveau document depuis le modèle Vide,
supprime la table créée par défaut et colle le contenu du presse-papiers.
Il envoie enfin la commande d'impression.

--=====

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 or an Application : print_a_table.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.

Select a subset of a table, a table or even several tables.
Go to the Scripts Menu, choose Numbers, then choose "print_a_table"
The script create a new document based on the Blank template,
remove the default table and paste the clipboard's contents.
At last, it issue the print command.

--=====

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/02/20
*)
--=====

property theApp : "Numbers"
property sheet1 : "my first sheet"
property sheet2 : "my second sheet"
property tableToCopy : "Table_to_copy"

--=====

on run
	-- run script do_your_duty
	my do_your_duty()
end run

--===

on do_your_duty()
	--script do_your_duty
	
	my activateGUIscripting()
	
	my selectSheet(1, sheet2)
	
	tell application "Numbers" to tell document 1 to tell sheet sheet2 to tell table tableToCopy
		set selection range to range ("A1:" & name of last cell)
	end tell
	
	(*
Copy the selected items *)
	my raccourci(theApp, "c", "c") (* cmd + c *)
	(*
Create a new document based upon Blank.template *)
	set myNewDoc to my makeAnIworkDoc(theApp)
	(*
Delete the default table *)
	tell application "Numbers" to tell document 1 to tell sheet 1 to delete table 1
	
	my raccourci(theApp, "v", "c") (* cmd + v = Paste *)
	
	my raccourci(theApp, "p", "c") (* cmd + p = Print *)
	my raccourci(theApp, return, "") (* return = validate the Print command*)
	
	--end script
end do_your_duty

--=====
(*
Creates a new iWork document from the Blank template and returns its name.
example:
set myNewDoc to my makeAnIworkDoc(theApp)
*)
on makeAnIworkDoc(the_app)
	local maybe, path_to_the_App, nb_doc, doc_name
	if the_app is "Pages" then
		tell application "Pages"
			set nb_doc to count of documents
			make new document with properties {template name:item 1 of templates}
		end tell
	else if the_app is "Numbers" then
		tell application "System Events" to set maybe to the_app is in title of every application process
		if not maybe then tell application theApp to activate
		tell application "System Events"
			set path_to_the_App to get application file of application process the_app
		end tell
		tell application "Numbers"
			set nb_doc to count of documents
			open ((path_to_the_App as text) & "Contents:Resources:Templates:Blank.nmbtemplate:")
		end tell
	else
		if my parleAnglais(theApp) then
			error "The application "" & the_app & "" is not accepted !"
		else
			error "l'application « " & the_app & " » n'est pas gérée !"
		end if
	end if
	
	tell application the_app
		repeat until (count of documents) > nb_doc
			delay 0.1
		end repeat
		set doc_name to name of document 1
	end tell -- the_App
	return doc_name
end makeAnIworkDoc

--=====

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 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

--=====
(*
==== Uses GUIscripting ====
	
most of this handler is from Nigel Garvey
*)

on selectSheet(theDoc, theSheet)
	script myScript
		property listeObjets : {}
		local maybe, targetSheetRow
		
		tell application "Numbers"
			activate
			set theDoc to name of document theDoc (* useful if the passed value is a number *)
			tell document theDoc to set my listeObjets to name of sheets
		end tell -- "Numbers".
		
		set maybe to theSheet is in my listeObjets
		set my listeObjets to {} -- So it will not be saved in the script *)
		if not maybe then
			if my parleAnglais() then
				error "The sheet "" & theSheet & "" is unavailable in the spreadsheet "" & theDoc & "" !"
			else
				error "La feuille « " & theSheet & " » n'existe pas dans le tableur « " & theDoc & " » ! "
			end if -- my parleAnglais
		end if -- not maybe
		
		set maybe to 5 > (system attribute "sys2")
		tell application "System Events" to tell application process "Numbers"
			tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theDoc
				if maybe then (* macOS X 10.4.x
'(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
					set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is theSheet))
				else (* macOS X 10.5.x or higher *)
					set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is theSheet)) or (value of first group's first static text is theSheet))
				end if -- maybe.
				
				tell targetSheetRow to set value of attribute "AXSelected" to true
				set cnt to 0
				repeat (*
Must way that Numbers becomes ready to receive the value *)
					try
						tell targetSheetRow to set value of attribute "AXDisclosing" to true
						exit repeat
					on error
						set cnt to cnt + 1
						delay 0.5 -- half a second
					end try
				end repeat
			end tell -- outline.
		end tell -- "System Events".
		
		tell application "Numbers" to tell document theDoc to tell sheet theSheet to tell table 1
			with timeout of 20 * 60 seconds (*
WITH this setting, the script will be able to wait 20 minutes for the asked value.
I hope that the document will not be so huge that this delay prove to be too short. *)
				value of cell "A1"
			end timeout
		end tell -- "Numbers".
		
		tell application "System Events" to tell application process "Numbers" (*
Do the trick one more time to be sure that the sheet is open *)
			tell targetSheetRow to set value of attribute "AXDisclosing" to true
		end tell -- "System Events".
		
	end script
	run myScript
end selectSheet
--=====
--[/SCRIPT]
--{code}

Yvan KOENIG (VALLAURIS, France) mardi 1 mars 2011 22:35:10

Sorry Yvan I don’t wish to sound ungrateful but for somebody who has only had a Mac for a month and it is the first time using Applescript your script is complicated to me. There are a lot of keywords that you are using that I have never seen before and others that I have seen that are being used in a different way. It is a lot for my poor old brain to take in. Now I know that currently I can only print the visible table using Applescript I can simplify what I have done so that instead of having my work in three separate tables it can all be in one so that each appears on a separate printable page. As they say in the advert “Simples”

ElBeardo :slight_smile:

Most of the different functions used are described in the available resources :

AppleScript Language Guide
AppleScript’s dictionary of Applescript aware applications or OSAXen.

In the script, I use AppleScript’s functions from

plain AppleScript
Standard Additions
System Events
Pages

And of course the script define and use its own variables and handlers.

I know that the SelectSheet handler is a bit complicated. I asked Nigel’s help because I was unable to find some tips by myself.
The Raccourci one may seem to be complicated. In fact it’s really simple, it just give me the ability to use the same code when I want to issue a shortcut like : command + option + shift + v.

Yvan KOENIG (VALLAURIS, France) mercredi 2 mars 2011 10:13:56

Yvan I have been using the publications you describe to aid me with my scripts but I think perhaps you misunderstand what I am trying to achieve. My MacBook Pro is a home computer, although I worked in the computer industry for many years I have been retired for 20 years and so I am not and don’t intend to be programming in Applescript every day. the scripts I produce will be for home not commercial use. In fact i doubt if I will ever write more than 2 or 3 Applescript programs, the same with Excel and VBA on the PC. I therefore want to keep things very simple so that if Applescript or Numbers change and my scripts no longer work (as again happened with Excel and VBA) I don’t want to have to spend weeks relearning Applescript and what I was doing to get it working again.

I therefore want to produce the most basic simple script that will achieve my requirements.

ElBeardo :slight_smile: