Re: Numbers '09 and AppleScript
Re: Numbers '09 and AppleScript
- Subject: Re: Numbers '09 and AppleScript
- From: KOENIG Yvan <email@hidden>
- Date: Sat, 21 Feb 2009 16:39:50 +0100
Here is a soluce.
--[SCRIPT]
--=====
property theApp : "Numbers"
--=====
my duplicateSheet("theSheet", "Clément")
my duplicateTable("Feuille 1", "Tableau 2", "La Joconde")
--=====
on duplicateSheet(sourceSheet, newName)
tell application "Numbers"
activate
tell document 1 to set lesFeuilles1 to name of sheets
end tell
if sourceSheet is not in lesFeuilles1 then
if my parleFrancais() then
error "La feuille “" & sourceSheet & "” n'existe pas ! "
else
error "The sheet “" & sourceSheet & "” is missing ! "
end if
end if
(*
Calculates the index of the source sheet name in the thumbnails area.
A sheet may have the same name than a table *)
if newName is not in lesFeuilles1 then
tell application "Numbers" to tell document 1
set indx to 0
repeat with s from 1 to count of lesFeuilles1
set indx to indx + 1
set nSheet to item s of lesFeuilles1
if nSheet is sourceSheet then
exit repeat
else
set indx to indx + (count of tables of sheet nSheet)
end if
end repeat
end tell (*
here indx is the index of the source sheet in the list of rows *)
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
select row indx
end tell
keystroke "d" using command down
end tell
tell application "Numbers" to tell document 1
set lesFeuilles2 to name of sheets
repeat with f in lesFeuilles2
if f is not in lesFeuilles1 then
set name of sheet f to newName
exit repeat
end if
end repeat
end tell
end if -- newName is not
end duplicateSheet
--=====
on duplicateTable(sourceSheet, sourceTable, newName)
tell application "Numbers"
activate
tell document 1
set lesFeuilles1 to name of sheets
if sourceSheet is in lesFeuilles1 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 missing ! "
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 missing ! "
end if
end if -- sourceSheet is in
end tell -- document
end tell -- application
(*
Calculates the index of the source table name in the thumbnails area.
A sheet may have the same name than a table *)
if newName is not in lesTables1 then
tell application "Numbers" to tell document 1
set indx to 0
set found to false
repeat with s from 1 to count of lesFeuilles1
set indx to indx + 1 (* add the sheet's row *)
set nSheet to item s of lesFeuilles1
if nSheet is sourceSheet then
repeat with t from 1 to count of lesTables1
set indx to indx + 1 (* add the table's row *)
if item t of lesTables1 = sourceTable then
set found to true
exit repeat
end if
end repeat
else
set indx to indx + (count of tables of sheet nSheet) (* add
every rows of the sheet *)
end if
if found then exit repeat
end repeat
end tell (*
here indx is the index of the source table in the list of rows *)
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
select row indx
end tell
keystroke "d" using command down
end tell
tell application "Numbers" to tell document 1 to tell sheet
sourceSheet
set lesTables2 to name of tables
repeat with t in lesTables2
if t is not in lesTables1 then
set name of table t to newName
exit repeat
end if
end repeat
end tell
end if -- newName is not
end duplicateTable
--=====
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 samedi 21 février 2009 16:39:28)
_______________________________________________
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