Q: Gui scripting using AppleScript not working
Before i get too complicated, I am starting with getting a basic copy/paste using keyboard shortcuts to work. In theory if i can copy a cells value into another cell using keyboard shortcuts, i can use any keyboard shortcuts i need for more complicated scripts.
Can someone more knowledgable than I look over the below core code and tell me what i am doing wrong?
(I have added script editor to accessibilities security settings to allow it to control the computer.)
My code for a simple copy/paste in numbers (other programs also don't respond):
on run
tell application "Numbers"
activate
if not (exists document 1) then error number 1000
tell document 1
tell active sheet
set the selectedTable to (the first table whose class of selection range is range)
set myRows to count the rows in selectedTable
tell selectedTable
set the selection range to cell 2 of row 3
sendCopy
set the selection range to cell 4 of row 3
sendPaste
end tell
end tell
end tell
end tell
end run
on sendCopy()
tell application "Numbers" to activate
tell application "System Events"
tell application process "Numbers"
keystroke "C"
end tell
end tell
end sendCopy
on sendPaste()
tell application "Numbers" to activate
tell application "System Events"
tell application process "Numbers"
keystroke "V"
end tell
end tell
end sendPaste
Thanks
Jason
iPad, iOS 9.3.2, iPad, macMini, iPhone
Posted on Jun 19, 2016 11:08 AM
I did already set script editor as allowed in security
but i thinking just figured it out.
I removed the subroutines, and converted them into code within the original script (i.e. not use subroutines for copy/paste. just repeat the code every time i need it, which i hate doing but i wanted to make sure it wasn't some applescript format issue) this got a reaction from numbers finally.
BUT it was bringing up the color dialog every time! which is not the same keyboard shortcut. Its Shift-Command C... wait a second....
turns out we both typed a capital C, which keystroke interpreted as Shift C.
When i turn it a lower case c, move all the code back in the main routine, it finally works.
Here is the final code:
on run
tell application "Numbers"
activate
if not (exists document 1) then error number 1000
tell document 1
tell active sheet
set the selectedTable to (the first table whose class of selection range is range)
tell selectedTable
set the selection range to cell 2 of row 3
tell application "System Events"
tell process "Numbers"
keystroke "c" using command down
end tell
end tell
set the selection range to cell 4 of row 3
tell application "System Events"
tell process "Numbers"
keystroke "v" using command down
end tell
end tell
end tell
end tell
end tell
end tell
end run
thanks for trying so hard for me.
Jason
Posted on Jun 20, 2016 6:20 PM