Bring launched app to foreground with focus - solved

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Posts: 219
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos

Bring launched app to foreground with focus - solved

Post by rumplestiltskin » Sat Jun 18, 2016 5:28 pm

I originally was posting this to ask a question but, as is most often the case, actually writing the post leads me to consider other options and, sure enough, I found my own answer. I thought it wise to post both the question and answer just in case others have this same issue (or if I forget next year what I did today :D ).

I'm writing an app to massage some data and then burn it to a disc by having LC launch an Automator app that brings up a window asking the user to select the files and, once the user does this, burns the file(s) to a CD/DVD. Everything works except that when I call the Automator app, the 'choose the files' window remains behind the LC app's window. I have to switch to it by clicking or Command-Tabbing.

The solution I found was this:

Code: Select all

on mouseUp
  launch "/Users/blevine/Desktop/Burn disc of" -- App remains in background so I need to do something more!
  do field "doThis" as AppleScript -- field "doThis" contains >> tell application "Burn disc of" to activate
 -- above line of code properly switches focus to the correct app
end mouseUp
I know the inclusion of spaces in the app's name is not wise so I will fix that.
The next step is to pass the name(s) of the appropriate files directly to the Automator app so all the user has to do is put in the appropriately sized disc (CD or DVD).

I know there's some terminal code that can accomplish this (hdiutil I think >> EDIT: drutil, not hdiutil) but that may be for the next version. But that also brings up another question: Is there common code to do this within LC or will I have to check the platform and use one of two different scripts depending of whether my app is running on macOS or Windows?


Posts: 421
Joined: Thu Mar 06, 2014 2:57 pm

Re: Bring launched app to foreground with focus - solved

Post by AxWald » Sun Jun 19, 2016 12:41 pm


for sure you need different code for different burning apps/ ways of burning.

In Win, I'd collect the desired data from within LC, put them into a freshly created folder within one of the approbate tmp-folders (%SystemRoot%\TEMP\MyFolder2Burn), and just tell the OS to burn it.
The last point might include a google session to find out the proper shell/ VBA cmd.

Have fun!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Mac OS”