Monday, November 16, 2015

macos - Switching to App in Dock



In Windows, I can swtich to the application that is opened in the taskbar using Windows + Number Key. Is there a similar shortcut key in mac to switch to opened applications in Dock. Or is there a way to assign shortcut keys to open applications.



Use Case:



I want to switch between my opened Firefox and Terminal and Sublime Text using shortcut keys, instead of using Alt + Tab.


Answer



There is no such feature built in. You have several options to achieve a similar effect yourself:





  • Use a launcher, such as Quicksilver or LaunchBar. They'll learn your preferences or let you assign keys to certain applications, so that you can quickly switch between applications no matter what their Dock positions are by e.g. typing a hotkey and a single letter.

  • Create scripts such as tell application " Terminal" to activate in AppleScript editor. You can assign them keyboard shortcuts in FastScripts.

  • Create Automator workflows with the Launch Application action for each of the programs, and assign keyboard shortcuts in System Preferences » Keyboard » Keyboard Shortcuts » Services.

  • For Terminal specifically, you could use Total Terminal, a hud-style terminal.







If you want to access the Dock item at a specific position rather than a specific application, you can use UI scripting in AppleScript: Enable the keyboard shortcut to focus the Dock in System Preferences » Keyboard » Keyboard Shortcuts » Keyboard & Text Input and Enable access for assistive devices in System Preferences » Accessibility. Now you can create a script such as the following script, which (usually) activates the third Dock icon from the left:



tell application "System Events"
# press Ctrl-F3
key down control
key code 99
key up control

# right arrow twice
key code 124

key code 124

# enter to confirm
key code 36

# focus Dock again
key down control
key code 99
key up control


move left twice to re-set to original position
key code 123
key code 123

# Escape to close
key code 53
end tell


It's not a reliable solution though, as the Dock remembers the last focused element and requires you to reset the position afterwards. Your own use of the keyboard to access the Dock will interfere with this script.



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...