Cycle between open apps by a key press

I am looking for a software that lets me press a keyboard key on a Mac and cycle between the currently open apps one at a time.

For example if I have Safari, Mail and Notes open with Mail as the active app, pressing the key should bring up say, Safari. Pressing the same key again should bring up Notes, then Mail on the next press of the same key and so on…

I am aware of the cmd+tab to bring up application switcher but trying to reduce the finger strain that comes with keeping the cmd key pressed down while pressing the tab.

Atm, I am using BetterTouchTool to have 4 on the numpad (am using an external keyboard) to press cmd+tab. The problem with this is that I can only switch between two apps - the current one and the previous one.

Any ideas or suggestions are appreciated.

This Hammerspoon script should do it. Once all the apps you want to cycle are launched, the switch is low latency.

hs.hotkey.bindSpec(
	{{"ctrl","alt"}, "c"},
	function()
		focusedApplication = hs.window.focusedWindow():application()
		if focusedApplication:title() == "Pages" then
			hs.application.launchOrFocus("Numbers")	
		elseif focusedApplication:title() == "Numbers" then
			hs.application.launchOrFocus("Keynote")	
		elseif focusedApplication:title() == "Keynote" then
			hs.application.launchOrFocus("Pages")	
		else
			hs.application.launchOrFocus("Pages")	
		end
		
	end
)

Thanks for that.

It should ideally be dynamic and work with whatever apps are currently open.

Looks like the names of the apps need to be hardcoded in the above script.

Gotcha. I ran into an issue grabbing the current apps dynamically, but if you don’t mind listing what you use in the applications variable, this will cycle through whatever’s currently open from that list.

hs.hotkey.bindSpec(
	{{"ctrl","alt"}, "c"},
	function()
		focusedApplication = hs.window.focusedWindow():application()
		applications = {'Pages','Numbers','Safari','Terminal','Reeder','Messages','Photoshop','DEVONthink 3','Spark','Keynote'}
		applicationsLastIndex = #applications
		currentApplication = focusedApplication:title()
		currentApplicationIndex = 1
		isAppSwitched = false
		
		for i,v in ipairs(applications) do
			if v == currentApplication then
				currentApplicationIndex = i
				break
			end
		end
		
		-- Search applications array after currently focused app
		for i,v in ipairs(applications) do
			if i > currentApplicationIndex then
				
				applicationSearchResult = hs.application.get(v)
				if applicationSearchResult ~= nil then
					print(currentApplication,v)
					hs.application.launchOrFocus(v)
					isAppSwitched = true
					break
				end
			end
		end
		-- Search applications array before currently focused app if needed
		if isAppSwitched == false then
			for i,v in ipairs(applications) do
				if i < currentApplicationIndex then
					
					applicationSearchResult = hs.application.get(v)
					if applicationSearchResult ~= nil then
						print(currentApplication,v)
						hs.application.launchOrFocus(v)
						isAppSwitched = true
						break
					end
				end
			end
		end
		
	end
)
2 Likes

@cornchip Thank you so much. It works nicely.

I will eat a bag of corn chips today to celebrate.

3 Likes