Startup Items Hide NOT working in Big Sur

Here’s the problem. Compile a simple app with 1 window, then add an entry to Startup Items and click the hide checkbox. I want the app to run at login and be hidden. This works in Mojave but NOT in Big Sur. I tried this with Big Sur’s Textedit and it works properly. Does anyone know of a work around for Big Sur? Currently, I don’t use the hide feature in Startup Items as I have to manually choose File Hide App to let it run but hidden from view. I’m running the current version of Xojo on a Macbook Pro 2014.

How about deselecting the default window and in app.activate, check to see if there’s a window and create one if there’s not.

I figured out a work around. I tried Greg’s suggestion but I could not get it to work properly. After checking to see if the problem was fixed (there had been 2 updates since I did the 1st post and sent feedback). Here’s my work around. I created an AppleScript app and leave it in the applications folder. I called the script and I give it full disk access in the privacy settings. I added the code to check for the Hide app and then open it. The app runs and hides my App and then the Hide app quits. This achieves the desired results and the only side effect is the user sees the App window appear briefly until the Hide app runs.

Interesting… :thinking: This difference probably means the OS sends a different event than before and Xojo doesn’t handle it out of the box.
Have you checked whether you receive an AppleEvent in such cases?

Or perhaps you could check your parent process (the one who started your app) and determine whether you’ve been launched as a startup item (assume you’re always starting invisibly if so), then hide your own app with existing declares. I’m not sure you can know whether your app has been launched from the system preferences mechanism, though (what component handles this opening)…

A third solution would be to use launchd (a Launch Agent app) instead of system preferences’ startup items section. That way, you surely can determine Launchd is your parent process and hide yourself.

My expertise level is very low. I wouldn’t know how to check if I received an Apple Event or how to use declares. I was successful with Launchd on a project I did a long time ago. I am self taught when it comes to programming and I learn by looking at other programmers code. Most of the time, I can’t find an example that is suitable. That is why it took me 4 months to find a work around. I use command h a lot. I never use minimize. I prefer to use command h to hide the front most window, so I can see the window behind. Then I use command tab to switch back and forth between the 2 apps that I am working with. This approach is much faster than manually moving the windows in order to see both at the same time. I wrote an app that uses rsync to backup my mail to a cloud service and the app runs when I log into my account. I don’t need to see the contents of the backup app. When it launches, I used command h to immediately hide it from view and it continues to run while hidden from view. I like to keep things simple. Sending an AppleScript code from my app hid the window in my app but the apple still stayed in the front until I clicked on another app. When I clicked on the app in the dock to see the window, the window did not appear no matter what I tried.

Look at the app class: you can add a HandleAppleEvent event to it. Then, you can show a MessageBox in there to monitor the events you get (in some events, you should avoid putting a MessageBox, but not in this one; an alternative would be System.DebugLog, but it’s a nightmare to use since Apple unified the logs in 10.13).

For the other things, do you have the MBS plugin, which would make things easier?
If not, we can find the declares otherwise.

P.S.: I don’t have Big Sur yet so I can’t make a workable example for you, sorry.

I added the HandleAppleEvent to the the App Class and the message box shows that it was triggered.
I do have and use the MBS plugins in order to talk to the midi instruments.

The correct way for macOS is to do this is by using an helper app and ServiceManager

For AppStore this has always been the only way anyway. But since macOS 10.12 it is also the only way to make it work.

BTW MBS has ServiceManagerModuleMBS which you can do this very easily.

Thanks for the info. I will have to look into this.