Tuesday, September 29, 2020
  • Index
  •  » Code Exchange
  •  » Apple's keyboard Input Shortcut could be used for GUI Scripting.

#1 2020-08-02 12:00:00 pm

Registered: 2019-10-23
Posts: 397

Apple's keyboard Input Shortcut could be used for GUI Scripting.

The process to do GUI scripting could lead to error or frustration when it breaks.

Apple have some build-in keyboard input shortcuts that we could use build something from.
This AS code include 9 handlers from DefaultShortcutsTable.xml but the key code I use maybe
do not work on your system. The code could give you some ideas how you could build
handlers that navigate your system with arrow keys in mind but instead of clicking on whose.
AS will do it for you... smile

This code is not in any way to replace normal GUI Scripting, its only other way or different.


* Apple have some default keyboard Input Shortcuts that do specific actions.
* Reference: DefaultShortcutsTable.xml

-- actionKeyboardTurnOnOff()

* Sometimes it could be very useful to be able to navigate windows, menu's and icons with arrow keys. Or to build small task on a remote location from mobile device.

handler could be...
ex. actionArrayKeysKind:direction:withCount

kind = Apple's shortcuts input keys action. (Keyboard > Shortcuts tab in System Preferences)
direction = 1 of (up, down, left or right)
withCount = how many times to repeat.

We only need key code's of Apple's Keyboard Input Shortcuts and
the arrow keys. That is 9 for Apple's and for the arrow keys its 4.
we could then build a if statement to for the handler.

ex. my actionArrayKeysKind:"Dock" direction:"right" withCount:"3"

it will activate the dock, move the arrow key to right direction 3 times... (step).


-- ### Move focus to the menu bar.
-- actionFocusMenubar()

-- ### Move focus to the Dock.
-- actionFocusDock()

-- ### Move focus to active or next window.
-- actionFocusActivateNextWindow()

-- ### Move focus to the window toolbar.
-- actionFocusWindowToolbar()

-- ### Move focus to the floating window.
-- actionFocusFloatingWindow()

-- ### Move focus to next window.
-- actionFocusNextWindow()

-- ### Move focus to the window drawer.
-- actionFocusWindowDrawer()

-- ### Move focus to status menus.
-- actionFocusStatusMenu()

-- ### Change the way Tab moves focus.
-- actionTabMovesFocus()

on actionKeyboardTurnOnOff()
   tell application "System Events"
       key code 122 using {control down}
   end tell
end actionKeyboardTurnOnOff

on actionFocusMenubar()
   tell application "System Events"
       key code 120 using {control down}
   end tell
end actionFocusMenubar

on actionFocusDock()
   tell application "System Events"
       key code 99 using {control down}
   end tell
end actionFocusDock

on actionFocusActivateNextWindow()
   tell application "System Events"
       key code 118 using {control down}
   end tell
end actionFocusActivateNextWindow

on actionFocusWindowToolbar()
   tell application "System Events"
       key code 96 using {control down}
   end tell
end actionFocusWindowToolbar

on actionFocusFloatingWindow()
   tell application "System Events"
       key code 97 using {control down}
   end tell
end actionFocusFloatingWindow

on actionFocusNextWindow()
   tell application "System Events"
       key code 101 using {control down}
   end tell
end actionFocusNextWindow

on actionFocusWindowDrawer()
   tell application "System Events"
       key code 109 using {control down}
   end tell
end actionFocusWindowDrawer

on actionFocusStatusMenu()
   tell application "System Events"
       key code 100 using {control down}
   end tell
end actionFocusStatusMenu

on actionTabMovesFocus()
   tell application "System Events"
       key code 98 using {control down}
   end tell
end actionTabMovesFocus

I could teach you to cook but I couldn't do anything if you do not have desire or commitment for it.


  • Index
  •  » Code Exchange
  •  » Apple's keyboard Input Shortcut could be used for GUI Scripting.

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)