Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

select cells numbers with applescript

Hi!


How can select the cells A1 A16 A31 A46 A61 with applescript?


And how can change the background of these cells with an image with applescript?


Thanks!

iMac, macOS Sierra (10.12.6), null

Posted on Dec 14, 2017 1:06 AM

Reply
Question marked as Best reply

Posted on Dec 14, 2017 3:40 AM

If you can copy that one image to the system clipboard (I did that by opening the image in Preview and choosing Edit > Copy from the menu) then the script below should do what you want.


Just add additional cell names to the list as needed.


SG


-- copy image to system clipboard before running

set tgtCellNames to {"A1", "A16", "A31", "A46", "A61"}

repeat with aName in tgtCellNames


pasteImgToCell(aName)

end repeat

to pasteImgToCell(cellName)

tell application "Numbers"

tell the first table of the active sheet of document 1

set selection range to cellcellName


activate

tell application "System Events" to keystroke "v" using command down

end tell

end tell

end pasteImgToCell

6 replies
Question marked as Best reply

Dec 14, 2017 3:40 AM in response to Karelias

If you can copy that one image to the system clipboard (I did that by opening the image in Preview and choosing Edit > Copy from the menu) then the script below should do what you want.


Just add additional cell names to the list as needed.


SG


-- copy image to system clipboard before running

set tgtCellNames to {"A1", "A16", "A31", "A46", "A61"}

repeat with aName in tgtCellNames


pasteImgToCell(aName)

end repeat

to pasteImgToCell(cellName)

tell application "Numbers"

tell the first table of the active sheet of document 1

set selection range to cellcellName


activate

tell application "System Events" to keystroke "v" using command down

end tell

end tell

end pasteImgToCell

Dec 14, 2017 1:43 AM in response to Karelias

It's easy to select cells with AppleScript but one needs to know the document, sheet, and table.


As for setting the background, that can't be done with AppleScript, though it might be possible to paste an image in.


Perhaps you could give more details of what you are trying to do, and why you need to do it using a script.


SG

Dec 14, 2017 2:27 AM in response to SGIII

Thanks SGIII !!!


I use this script to color the cells A1 A16 A31 A46 A61:



on run {input, parameters}

tell application "Numbers"

activate

tell the first table of the active sheet of document 1

set the background color of cell "A1" to {65535, 0, 0}

set the background color of cell "A16" to {65535, 0, 0}

set the background color of cell "A31" to {65535, 0, 0}

set the background color of cell "A46" to {65535, 0, 0}

set the background color of cell "A61" to {65535, 0, 0}

end tell

end tell

return input end run


I need to insert a background image in these cells.

If it isn't possible I thought to select the cells A1 A16 A31 A46 A61 with applescript and then change manually the background.


P.S. Actually the cells are many more, for this I need to use applescript.

select cells numbers with applescript

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