Shortcuts app: How to check which app is frontmost

I am trying to create a shortcut that does different things depending on which app is frontmost. I have found the "Is Frontmost" variable in the App category of shortcut inputs. When I place it in an "If" block however, I am unable to enter a variable to compare the frontmost app to. How do I do this?


Any and all help is appreciated! Please feel free to ask clarifying questions.


Windows

Posted on Dec 13, 2023 6:26 AM

Reply
1 reply

Feb 16, 2024 6:29 PM in response to Nurv288

I had this problem and solved it today with a small amount of AppleScript, inspired by this StackOverflow thread.


on run {input, parameters}
	tell application "System Events"
		set frontProcess to name of first process whose frontmost = true
	end tell
	return frontProcess
end run


I have the shortcut triggered by Shortery, which is a free way of adding Shortcuts Automation (present on iOS) to Shortcuts on macOS. Could also work great from the Share Sheet.


You could probably do the whole thing in AppleScript, but here's a sample program showing how you'd do the rest in Shortcuts, given a list of apps you want to compare against:



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Shortcuts app: How to check which app is frontmost

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