Applescript to paste into numbers

I want to be able to copy contents of clipboard into cell A1 of a certain table in numbers file. What applescript could I use to do this?

MacBook Pro

Posted on May 18, 2010 3:53 PM

Reply
16 replies

May 19, 2010 12:26 PM in response to KOENIG Yvan

(1) I added one instruction for users which hide name extension (which is a really bad idea).
Under 10.4.11, the problems linked to that exist but at least, we are forewarned of this choice because the document icon is no longer a Numbers one but a blank one.
Under 10.6.3, it remains the normal Numbers icon.

(2) Having inserted this sentence :

I choose B2 because the default tables have an header row and an header column.


in the script, I don't know what may be done to help users which work on a one cell table *_after writing here_* :
Not sure why this happened as Table 1 does exist in Sheet 1 and *_has lots of empty cells, its totally empty through to D9..._*


I must apologize for the typo in my late message, but my point of view remains the same : such askers are liars !

--

on run
(*
Activate GUI scripting which is required to trigger the Paste menu
*)
my activateGUIscripting()
(*
Ask "Standard Additions" to give the true path to the Desktop.
*)
set p2d to path to desktop as text
(*
Build the source and target pathnames
*)
set importFile to p2d & "Users:lholmes:Desktop:test.xls"
set liveName to "Live capture.numbers" --"Live.numbers"
set liveFile to p2d & liveName
(*
Here is an example of complete pathname.
Yours where wrong.
You used UNIX path replacing the slashs by colons.
The volume name was missing.
set liveFile to "Macintosh HD:Users:yvan_koenig:Desktop:Live.numbers" *)
(*
Check that the files which we plan to use are available.
*)
tell application "System Events"
set maybe1 to exists disk item importFile
set maybe2 to exists disk item liveFile
end tell -- Numbers
set errMsg to ""
if maybe1 is false then set errMsg to errMsg & "The file “" & importFile & "” is unavailable !"
if maybe2 is false then set errMsg to errMsg & "The file “" & liveFile & "” is unavailable !"
if errMsg is not "" then error errMsg

(*
I disable the Excel code because M…Soft products are not allowed to enter my machines
*)
(*
tell application "Microsoft Excel"
open importFile
copy range (range "a1:M500" of sheet "Sheet1.xls" of workbook importFile)
end tell
*)
(*
Instruction required for the users which hide extension names ;-(
*)
set windowName to displayed name of (get info for file liveFile)

tell application "Numbers"
activate
open liveFile
(*
Wait for a really open document
*)
repeat until exists window windowName (* checks for the true window name *)
delay 0.2
end repeat
(*
Define the first cell of the range in which we will paste.
I choose B2 because the default tables have an header row and an header column.
It's easier to remove them than to change them in standard row/column.
*)
tell document liveName to tell sheet 1 to tell table 1 to set selection range to range "B2"
end tell -- Numbers
(*
This time, I insert only the scheme triggering a menu item.
If like me you prefer triggering a shortcut,
grab the instruction and the handler from my late script.
*)
--my selectMenu("Numbers", 4, 6) -- Paste
my selectMenu("Numbers", 4, 7) -- Paste Matching Style
--my selectMenu("Numbers", 4, 8) -- Paste Values
end run
--=====
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
--=====
(*
Handler triggering the menu item mi of the menu mt of the application theApp.
*)
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
--=====
--


Yvan KOENIG (VALLAURIS, France) mercredi 19 mai 2010 21:26:28

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.

Applescript to paste into numbers

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