0

I developed a MacOS app with a GUI and I set it as A background only application in the Info.plist file.

enter image description here

In addition I added it to start-up applications in order to keep it working while Mac is turned on.

enter image description here

Now I want to open in foreground this application. I tried with in Terminal with open keyword but it has no effect. Is there a way to open a background app in the foreground?

2
  • Not sure I understand. If it is in Login Items, it should be already running. Can't you just Cmd-Tab to it?
    – nohillside
    Aug 17, 2022 at 14:49
  • If it is set as "Background only" the application doesn't appear in Cmd-Tab.
    – TechRevo
    Aug 18, 2022 at 7:41

2 Answers 2

0

The only way, I believe, to make visible an app whose "Info.plist" contains "Application is background only" is True, is to edit the plist file and set the value for "Application is background only" to False or No or 0.

This following AppleScript code will help you do exactly that… Very quickly

activate
set plistFile to POSIX path of (choose file with prompt ¬
    "Select a .plist file to edit from within an app's \"Contents\" folder." of type ¬
    "com.apple.property-list" with invisibles and showing package contents)

set appName to do shell script "defaults read " & quoted form of plistFile & " CFBundleName"

try
    set currentStateOfBackgroundOnly to do shell script "defaults read " & ¬
        quoted form of plistFile & " LSBackgroundOnly"
on error errMsg number errNum
    set currentStateOfBackgroundOnly to "0"
end try

if currentStateOfBackgroundOnly = "0" then
    set appStatus to appName & " Is NOT currently running in \"Background Only\" mode."
else
    set appStatus to appName & " IS currently running in \"Background Only\" mode."
end if

activate
set theChoice to (choose from list {"Run In Background", "Don't Run In Background"} ¬
    with title "Run " & appName & ".app in the background only?" with prompt ¬
    appStatus & linefeed & linefeed & "Would you like to run " & appName & ¬
    ".app in the background only?" OK button name "OK" cancel button name "Cancel") as text

if theChoice = "Run In Background" then
    do shell script "defaults write " & quoted form of plistFile & " LSBackgroundOnly" & " -bool True"
else if theChoice = "Don't Run In Background" then
    do shell script "defaults write " & quoted form of plistFile & " LSBackgroundOnly" & " -bool False"
end if

enter image description here

1
  • AppleScript works but application crashes.
    – TechRevo
    Aug 18, 2022 at 7:43
0

No, it is not possible to run a "background app" in the foreground.

It is not such that an app that has specified "LSBackgroundOnly" merely has its window set to the background and "hidden from view". The program actually runs in a context where it cannot open any windows at all.

You will need to set "LSBackgroundOnly" to false or remove the property in order to run the app with a GUI showing. Now it is no longer a "background app" - it's just an ordinary app.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .