Longshot - Briefly move application focus away from current app and then back lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- wizbowes · 2013-05-20 23:32 Bit of a long shot here but anyway. Is there a way to briefly move the application focus away from the current active application to somewhere else (say the desktop) and then back again to the application? I have a Delphi application that runs in the background and moves some files about.  This happens in the background whilst another application (Adobe Bridge - part of Photoshop) is the active window.  Bridge holds a cache of these files, and the only way I've found to force bridge to refresh the cache is for it to lose the focus, and then regain it.  This forces bridge to rescan and re-cache these files - picking up the changes I've made in the background. I easily do this in Windows using SetForegroundFocus and finding the handle for Bridge via the winapi. Toggling the application to lose focus and gain it again immediately is invisible to the user but does the trick.  I am seriously struggling to see how to do this on a Mac.  I'm brand new to Mac development and fairly new to FPC (I'd say a low intermediate level) - so any solution that requires anything outside the standard libraries may require some hand holding. Anyone got any ideas how I could do this? ---------------------------------------------------------------------- User137 · 2013-05-21 05:20 Never done anything with, or to MAC, but did a quick search. Instead of WinAPI, Mac seems to use Cocoa (there was also old and now deprecated Carbon). Search with "cocoa activate window" brings alot of results, 1 of them was: http://stackoverflow.com/questions/7055120/how-to-activate-a-window But do you have a pas header for Cocoa instructions for Lazarus? ---------------------------------------------------------------------- jwdietrich · 2013-05-21 12:36 You can do this easily with AppleScript. The activate command brings an application to the foreground (see http://developer.apple.com/libra ry/mac/#documentation/applescript/conceptual/applescriptlangguide/refe rence/ASLR_cmds.html for reference). It is quite easy to invoke AppleScript commands from Free Pascal, see http://www.lazarus.freepascal.org/index.php/topic,18903.msg107254.html #msg107254 for a simple example. ---------------------------------------------------------------------- jwdietrich · 2013-05-21 17:27 To deliver a working example the following button handler contains an embedded AppleScript that shortly activates first the finder and subsequently the TextEdit application. TextEdit is automatically started if it doesn't run. Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var   s: longint; begin   s := fpSystem('osascript -e ''tell the application "Finder" to activate''');   s := fpSystem('osascript -e ''tell the application "TextEdit" to activate'''); end; Edit: You will have to insert the Unix unit into the uses section in order to compile this code. ---------------------------------------------------------------------- wizbowes · 2013-06-07 20:47 thanks all.  For the record - I wasn't able to work this out in a sensible fashion within OSX so worked round round the problem insteadt....