How to bring an application to the front, no bouncing dock icons

In my AppleScript, I use activate to bring an application to the front. However, on machines of some colleagues, it doesn’t do that. The app-icon in the dock will bounce, but it doesn’t get put into the front. This is very annoying, because the user has to go to the app manually every time.

I suspect this is due to some setting or something. Any ideas how to accomplish this?

There was one version of the OS where that happened – could they be running an older version?

You can work around it by telling the app to “set frontmost to true” instead of “activate”. Apple broke it for a few releases, but it’s been fixed for a while now.

Hey Doeke,

If memory serves this is what I did for a workaround with system that had the activate bug:

tell application "TextEdit"
   if not running then
      run
      delay 0.25
   end if
   activate
end tell

And of course there’s always System Events:

tell application "System Events"
   tell application process "TextEdit"
      set frontmost to true
   end tell
end tell

-Chris

Chris (@ccstone), just in case someone needs this, I want to repost a solution you provided me to ensure that the Finder is frontmost.

From https://forum.keyboardmaestro.com/t/how-to-close-finder-tab/1894/13?u=jmichaeltx

------------------------------------------------------------
set myDesktop to path to desktop
------------------------------------------------------------
tell application "System Events"
  if quit delay ≠ 0 then set quit delay to 0
  tell application process "Finder" to set frontmost to true
end tell
------------------------------------------------------------
tell application "Finder"
  if (insertion location as alias) = myDesktop then
    if (count of windows) > 0 then
      set index of window 1 to 1
    end if
  end if
end tell
------------------------------------------------------------

It might be it is happening on older versions. We still have some El Capitan and Yosemity installations. Good reason to upgrade, if that is the problem.

Resurrecting this thread because a very similar AppleScript that I have used for several years stopped working all of the sudden.

Chris (@ccstone) the script below contains four methods I have tried (in conjunction with a Keyboard Maestro macro), but none of them work.

The top one was the original that worked for a long time, and I just noticed today it stopped. The second one is another method I tried, it doesn’t work either. The next two are the ones from this thread that also do not work.

It may be some temporary bug that a system restart will fix, but since I’m working I’m not able to restart right now. Wondering if anybody has any insight into this.

--get variable from Keyboard Maestro
tell application "Keyboard Maestro Engine"
	--set appName to getvariable "Current front application"
	set appName to "TextEdit"
end tell

--original method, stopped working
tell application appName to activate

--another thing I tried, doesn’t work
tell application appName to run

--doesn’t work either
tell application "System Events"
	tell application process appName
		set frontmost to true
	end tell
end tell

--doesn’t work either
tell application appName
	if not running then
		run
		delay 0.25
	end if
	activate
end tell

appName

Hey Chris,

If none of those are working then you need to reboot…

-ccs

Thanks Chris, I rebooted but for some reason none of them are working still.

When ran from within SD the application does flash to the front for a split second (with all four methods), but then SD comes back to the front.

When ran from within KM nothing at all happens. Maybe it’s something wrong with my macro, but I doubt it since it has been working fine for several years. I’ll keep tinkering with things.

EDIT: I figured it out. I had set the timeout on the AppleScript action in KM to 1 one-hundredth of a second and that was causing it to fail. I set the timeout that way because occasionally as of late it would show the select application dialog box as if it couldn’t find the correct application to recall. I never figured out why it was doing that so I set the timeout really short to have that dialog disappear right away. 🤷🏻

-Chris