0

I'd like to show & give focus to and hide an app using a single shortcut. The app (or apps) i like to use this way do not natively support this on their own. Is this possible on macOS (10.15 in my case)? Maybe using some 3rd party app or Automations?

I'm using this with iTerm2, it's called "Show/hide all windows with a system-wide hotkey", also, Launchbar has this feature but i'd like the same behaviour in PCalc and/or Calcbot.

2

This answer is a step by step explanation of what ankii proposed in a comment.

First, open Script Editor and write an Apple Script to toggle the visibility of your application. The following code should work, just change the value of appName (currently set to Finder) to be the app you want.

set appName to "Finder"

tell application "System Events"
    if visible of application process appName is true then
        set visible of application process appName to false
    else
        set visible of application process appName to true
    end if
end tell

Save this Apple Script as an application (File -> Save -> File Format -> Application). I named it Toggle Visibility, but you can call it anything.

Next, open Automator and create a new Quick Action (previously a called a service). Change the values in the drop down menu so that "Workflow receives no input in any application" is displayed at the top.

Drag Launch Application from the list of options on the left (you can use the search bar to find it) into your workflow. Set the selected application to other, and find the Apple Script you saved as an application previously.

Go to File -> Save to save your Quick Action, and give it a name.

Finally, open System Preferences and go to Keyboard -> Shortcuts -> Services, and scroll down to the General Tab. There, you should see the name of your Quick Action you just saved. Click the check box to enable it, and add a keyboard shortcut to activate it. Make sure the shortcut you added doesn't conflict with other shortcuts on your computer.

  • @trurl No problem. What is the "almost working" part of it for you? – beninato Dec 10 '19 at 23:27
  • Thanks, that (almost) worked as intended! I modified the script and added a line which sets the focus to Calcbot (so that i can start typing right away) [...] else set visible of application process "Calcbot" to true tell application process "Calcbot" to set frontmost to true Then, i added the following to the Info.plist within the .app-Package created by the script editor: <key>NSUIElement</key> <string>1</string> This suppresses the dock icon of the script/app and speeds up everything considerably. Thanks! – trurl Dec 10 '19 at 23:31
  • The formatting hints for comments do not work for me, i'm sorry – trurl Dec 10 '19 at 23:35
  • tell app "System Events" to tell the process named appName to set visible to not visible – CJK Dec 16 '19 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .