• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Rép: Numbers '09 and AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rép: Numbers '09 and AppleScript


  • Subject: Rép: Numbers '09 and AppleScript
  • From: KOENIG Yvan <email@hidden>
  • Date: Mon, 23 Feb 2009 15:55:49 +0100

Hi

The late version assumed that every sheet was 'expanded' in the thumbnail area.
Here is an enhanced version which requires that only for the sheet containing the table to duplicate.


--[SCRIPT]
--[SCRIPT duplicate Sheet and Table]

(*
CAUTION:
the sheet containing the table to be duplicated MUST be 'expanded' !

Yvan KOENIG (Vallauris, FRANCE)
21 février 2009
*)

--=====

property theApp : "Numbers"

--=====

my duplicateSheet("theSheet", "Clément")
my duplicateTable("Feuille 1", "Tableau 2", "La Joconde")

--=====

on duplicateSheet(sourceSheet, newName)
local lesFeuilles1, listOfRows, i, lesFeuilles2
tell application "Numbers"
activate
tell document 1 to set lesFeuilles1 to name of sheets
end tell -- Numbers

if sourceSheet is not in lesFeuilles1 then
if my parleFrancais() then
error "La feuille “" & sourceSheet & "” n'existe pas ! "
else
error "The sheet “" & sourceSheet & "” is unavailable ! "
end if -- my parleFrancais
end if -- sourceSheet

if newName is not in lesFeuilles1 then
(*
Now, an ugly workaround to duplicate the sheet *)
tell application "System Events" to tell (first process whose title is "Numbers")
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
select row 1
set value of attribute "AXFocused" to true
set listOfRows to name of static text of every row
repeat with i from 1 to count of listOfRows (*
We know that there is a sheet named sourceSheet
but maybe there is a table with the same name.
We check that we are really pointing the sheet item. *)
if my isItAsheet(item 1 of item i of listOfRows) then
select row i
exit repeat
end if -- my isItAsheet…
end repeat
end tell -- outline
keystroke "d" using command down
end tell -- application
(*
Rename the new sheet according to the passed name: newName *)
tell application "Numbers" to tell document 1
set lesFeuilles2 to name of sheets
repeat with i in lesFeuilles2
if i is not in lesFeuilles1 then (*
Here i is the name of the newly created sheet *)
set name of sheet i to newName
exit repeat
end if -- i is not…
end repeat
end tell -- document 1 of Numbers
end if -- newName is not…
end duplicateSheet


--=====

on duplicateTable(sourceSheet, sourceTable, newName)
local lesFeuilles, lesTables1, found, listOfRows, cor, i, nameI, j, lesTables2
tell application "Numbers"
activate
tell document 1
set lesFeuilles to name of sheets
if sourceSheet is in lesFeuilles then
tell sheet sourceSheet to set lesTables1 to name of tables
if sourceTable is not in lesTables1 then
if my parleFrancais() then
error "La table “" & sourceTable & "” de la feuille “" & sourceSheet & "” n'existe pas ! "
else
error "The sheet “" & sourceTable & "” of sheet “" & sourceSheet & "” is unavailable ! "
end if
end if -- sourceTable is not
else
if my parleFrancais() then
error "La feuille “" & sourceSheet & "” n'existe pas ! "
else
error "The sheet “" & sourceSheet & "” is unavailable ! "
end if
end if -- sourceSheet is in
end tell -- document
end tell -- application

if newName is not in lesTables1 then
tell application "System Events" to tell (first process whose title is "Numbers")
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
select row 1
set value of attribute "AXFocused" to true
set found to false
set listOfRows to name of static text of every row (* CAUTION, it's a list of lists !
{{"Feuille 2"}, {"Tableau 1"}, {"theSheet"}, {"Feuille 1"}, {"Tableau 2"}, {"Clément"}, {"Feuille 4"}} *)
set cor to count of listOfRows
repeat with i from 1 to cor (*
Scan the thumbnails *)
set nameI to (item 1 of item i of listOfRows)
if (sourceSheet = nameI) and my isItAsheet(nameI) then (*
Here we reached the thumbnail of sourceSheet *)
if (i < cor) and not my isItAsheet(item 1 of item (i + 1) of listOfRows) then (*
Here we may scan the thumbnails of tables of sourceSheet *)
repeat with j from i + 1 to i + (count of lesTables1)
if sourceTable = item 1 of item j of listOfRows then
select row j
set found to true
exit repeat
end if -- sourceTable
end repeat
else
if my parleFrancais() then
error "La table “" & sourceTable & "” de la feuille “" & sourceSheet & "”" & return & " n'est pas affichée dans les vignettes ! "
else
error "The sheet “" & sourceTable & "” of sheet “" & sourceSheet & "”" & return & " is not revealed in thumbnails ! "
end if -- my parleFrancais
end if -- i < …
end if -- (sourceSheet =
if found then exit repeat
end repeat -- i
end tell -- outline …
keystroke "d" using command down
end tell -- System Events…

tell application "Numbers" to tell document 1 to tell sheet sourceSheet
set lesTables2 to name of tables
repeat with i in lesTables2
if i is not in lesTables1 then (*
Here i is the name of the newly created table *)
set name of table i to newName
exit repeat
end if
end repeat
end tell
end if -- newName is not…
end duplicateTable


--=====

on isItAsheet(s)
	try
		tell application "Numbers" to tell document 1
			count of tables of sheet s (*
Post an error if s is not a sheet *)
		end tell
		return true
	on error
		return false
	end try
end isItAsheet

--=====

on parleFrancais()
	local z
	try
		tell application theApp to set z to localized string "Cancel"
	on error
		set z to "Cancel"
	end try
	return (z = "Annuler")
end parleFrancais

--=====
--[/SCRIPT]

Yvan KOENIG (from FRANCE lundi 23 février 2009 15:45:31)




_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Rép: Numbers '09 and AppleScript
      • From: KOENIG Yvan <email@hidden>
  • Prev by Date: Unpair paired device
  • Next by Date: Re: Mount volume.
  • Previous by thread: Unpair paired device
  • Next by thread: Re: Rép: Numbers '09 and AppleScript
  • Index(es):
    • Date
    • Thread