Apple Script Help: Check if an app is running [HazeOver]

the top one is the one currently displayed. the bottom one is the one I want it to switch to when I tap the button, but it doesn't. the trigger still activates and deactivates HazeOver, but the icon doesn't change.

And if you trigger the button, then run the widget scrip in the Script Editor right afterwards, does the script return the correct result?

I don't understand what you mean...

Let me turn it the other way around, what does the toggle (the associated action) do? What happens if you just tap the button, independent to the script of the widget.

  1. Run the Apple Script in the Apple Script Editor
  2. Tap your Touch Bar button
  3. Run the Apple Script in the Apple Script Editor

Does the result change?

no it doesn't

ive just quit the app hazeover and it now does return 'quit'

That's what I thought. What does the associated action do? If it does not quit/launch the app, then it will have no effect on your widget, as that's what the script is checking.

it activates and deactivates hazeover, command control option H

That's what I thought. Your widget checks wether your HazeOver is running or not, wether the script de/activates it (checks if it is frontmost).

Try this script:

return application (path to frontmost application as text)

and set as Regex value HazeOver.


That sounds like the solution :slight_smile:

By the way, the original script he posted should work for finding whether an app is running or not. It's using a new but not yet documented call is_app_running which should be much more performant than the standard Apple Script way. It's not yet documented because I need to do some more testing with it.


Ohhhhhh :star_struck:

doesn't work. when HazeOver is activated, it doesnt come to the front (but idk if that affects the coding)

What does ⌃⌥⌘H do?

And I don't understand what you mean here :frowning: an app is activated when it's frontmost.

maybe you should download HazeOver and try the free trial to test it yourself.
HazeOver is an icon in the menu bar, that when clicked, this shows:
Screenshot of Safari (15-08-20, 11-59-45 AM)

So when I press ⌃⌥⌘H, it doesn't quit the app, it simply deactivates what the app is doing: dimming background apps. I keep HazeOver open all the time, but when I Command-Tab, it doesn't appear there like a normal app.

Once you say everything…
The widget it not suitable at all for what you are looking to achieve. To make some confusion clear, HazeOver will always be

  • Running
  • Never be active (I guess - unless a preference window or something is open)

HazeOver will always be there, you can compare it to your Web browser: whereas the Browser might display a webpage or not, HazeOver might dim the other apps or not.

Three ways that I can think about to get what you want:

  1. Check if there is a process in the Activity Monitor that appears only when HazeOver dims the windows. You would have to check if this Process exists to toggle the widget dependently.
  2. Use Apple Script to access the right Menu Bar items and search for the existence of the menu. "Turn HazeOver On/Off". Bugger, I have no clue at all how to access these "Menu Bar Apps" (if someone knows, I'd be into it)
  3. If you only use the button to toggle HazeOver, you might work with a persistent variable inside BTT that would be changed as an associated action of the button/the keyboard command. The script would have to search for the variable. But you will have to figure this out on your own, my final exam does not allow me rn to try to discover new stuff here. This might help though:
1 Like

ahh, thank you and sorry for not being clear.
@Andreas_Hegenberg, why can't there just be a more simple alt. icon option?

Isn’t the alternate icon option already very easy? How would you make this easier?


Had a look at your App. According to the documentation, HazeOver has full Apple Script support. You should start to read there, using the Dictionary in Script Editor to find the command you need to get the information you need returned.

Automate with AppleScript

HazeOver can be fully controlled using AppleScript. You can toggle it, change dimming intensity, tint, animation duration, secondary display mode and multiple windows preference. Here’s how to try it out:

  • Launch “AppleScript Editor” application;
  • Select “File” > “New” menu;
  • Paste this text into the script window:

tell application "HazeOver" to set intensity to 70

  • Select “Script” > “Run” menu

HazeOver should instantly change dimming intensity. To find out all supported properties you need to add HazeOver app to AppleScript Editor library:

  • Locate “HazeOver” application in your “Applications” folder;
  • Drag-n-Drop “HazeOver” app on the “AppleScript Editor” Dock icon.

Available scripting properties can be found in “HazeOver Suite” > “application” section.

Now you have the tools to build what you want.

1 Like

couldn't you make it available for non-applescript buttons and make it able to change when wanted?