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
MacBook Pro
I choose B2 because the default tables have an header row and an header column.
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..._*
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
--=====
--
Applescript to paste into numbers