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

finder

(Doeke Zanstra) #1

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?


(Shane Stanley) #2

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


(Steve Mills) #3

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.


(Christopher Stone) #4

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


(Jim Underwood) #5

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
------------------------------------------------------------

(Doeke Zanstra) #6

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.