How to toggle instead of activate an app

Hello,
I often consult special apps like dictionaries and other references while I am working.
I am able to create a macro to activate (display) the app (or websites converted to apps with Fluid), and another one to hide it (activate app followed by Cmd-H). Please note that the solution is not to simply type Cmd-H because I am usually not in the app itself when I want to hide it.
I would like to avoid having to create 2 macros: one to activate and one to hide.
Is there any way to toggle the app activation: ie the macro activates it if it is not being displayed and hides it if it is being displayed?
thanks very much in advance for your time and help

Hey @ronald

Give this a try.

The same thing can be done with Keyboard Maestro actions.

  • If (application condition)
  • Hide specific application.
  • Show specific application.
  • Activate a specific application.

I'm not sure how Fluid distinguishes between the apps it creates, but there's probably a way to work with them. Todd is pretty bright.

-Chris


Toggle Visibility of a Running Application (activate if not running).kmmacros (2.7 KB)

1 Like

works perfectly: thank you so much !

it works fine, except for one dictionary app called dict.cc created with Fluid. I deleted and re-created the app, giving the name dictcc (without the '.') but for some crazy reason, if it is not named properly dict.cc, it will not run.
I created ➜ deleted ➜ re-created it 10 times to confirm this.
I created the macro below which works.
Your macro above will not run if I replace textedit with dict.cc, probably because the '.' is a reserved symbol.
Is there a work around you could think of ?
thanks very much

image

If KM actions work where the AppleScript doesn't, recreating the script's logic in KM would seem to be the way to go:

Dict.cc app.kmmacros (5.8 KB)
image

1 Like

Works perfectly as a macro with dict.cc.
thank you so much !!

1 Like

Hey @ronald,

I did mention there might be an issue with Fluid apps..

Make sure your dict.cc app is running and then run this from the Script Editor.app:

tell application "System Events"
   return name of application processes whose background only is false
end tell

See what the system thinks the name of your app is.

How to approach the problem depends upon the answer.

-Chris

1 Like

Hello CC,

Sorry for the delay.

I would like to apologize. I very much appreciated your script, and I gave the impression I was sidelining it.

You are right: you did mention that there may be an issue with Fluid.

I did not mention that based on your email, I tried your script with other Fluid created apps and they worked. I concluded that somehow the apple script does not tolerate a ‘.’ in the app name, hence my response above.
I did not have the problem with GGllick’s macro.

This is the result of your test with script editor.app and dict.cc active:

{“Finder”, “Path Finder”, “Carbon Copy Cloner”, “Keyboard Maestro”, “Moom”, “ScanSnap Manager”, “LaunchBar”, “Messages”, “app_mode_loader”, “Vivaldi”, “Google Chrome”, “Evernote”, “Print Selection”, “CloudPull”, “System Preferences”, “P-touch Editor”, “Mail”, “PrinterProxy”, “Touché”, “Snagit 2018”, “Notes”, “Numbers”, “PrinterProxy”, “handyPrintPro”, “Preview”, “PDF Expert”, “Pages”, “FluidApp”, “TextEdit”, “Fluid”, “Activity Monitor”, “FluidApp”, “Scrivener”, “SimpleMind”, “OmniOutliner”, “firefox”, “BetterTouchTool”, “Script Editor”}

thanks again very much CC

Hey @ronald,

That ought not to be an issue.

Hmm... I don't see a “dict.cc” listed there – only FluidApp and FluidApp.

What happens when you run this?

tell application "dict.cc"
   activate
end tell

-Chris

1 Like

Hello Chris,

Thank you for thinking about it.

I repeated both tests just to be sure. In both cases, my screenshot includes the dict.cc floating window.

Just in case this is relevant: I use Fluid to create URL apps mostly because @Tom brought to my attention the fact that Fluid allows for the create of apps with floating windows which is extremely useful for web sites used as a technical reference.

Hey @ronald,

I downloaded Fluid, made a couple of apps, and ran some tests.

There definitely are oddities when you have more than one Fluid app running at once.

I've filed a bug with Todd Ditchendorf, and we'll see what he does about it.

-Chris

1 Like

You are fantastic. I am speechless!!