How to start App with no Window and without Icon in Dock?

If you need an Helper to Autostart your App when user login-in, look this https://forum.xojo.com/12479-helper-apps-and-the-sandbox/last

Quick question: I assume that to make this a toggle preference the app should be able to rewrite the plist’s value and after an app restart have the new behaviour.

Is this allowed in sandboxed apps? Rewriting the app’s bundle plist?

[quote=100954:@Eduardo Gutierrez de Oliveira]Quick question: I assume that to make this a toggle preference the app should be able to rewrite the plist’s value and after an app restart have the new behaviour.

Is this allowed in sandboxed apps? Rewriting the app’s bundle plist?[/quote]

I am working right now on an app that may start without menu nor icon in the dock. I am just wondering if it will ever pass the MAS reviewer like that. I had an app rejected last year because it did not have the menu items required by Apple UI guidelines : File, Edit, and Window. Once I added them without enabling the first two and allowing switch between help and main window, it got accepted. So the Down syndrome guy was happy.

I also noticed that an app that starts that way does not get focus when launched. It runs in the back of the currently front app.

Well, if menus and icon are mandatory, I will simply use them. Paris is worth a mass, in the MAS :wink:

Rewriting the plist is an absolute no-no. Maybe you could use the launcher technology to actually have two apps : one with no icon and menu, the second with all the trimmings. To toggle, one would launch the other and quit ?

[quote=85341:@Sascha S]I am now automating it using a Post Build Script for OS X only:

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSUIElement"" 1")

BTW: I am doing the same for making my App retina enabled :wink:

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSHighResolutionCapable"" YES")[/quote]
Just seen this… This method is not 100% reliable.

You also need the key NSPrincipleClass to stabilize Retina, I can’t explain why as I honestly don’t know, but simply just setting NSHighResolutionCapable can cause it to randomly not display in Retina.

Sam,
Do you mean like this:

Dim App As String = CurrentBuildLocation + "/""" + CurrentBuildAppName + ".app""" Call DoShellCommand("/usr/bin/defaults write " + App + "/Contents/Info ""NSPrincipleClass"" 1")

Richard, you are correct.

Thanks - I wasn’t sure if it should read 1 or True, or something completely different :slight_smile:

It doesn’t actually matter what you put in as Xojo doesn’t use the Objective-C loader.

I’ve done it by setting the NSUIElelment value in the plist and then on launch call

[code] declare sub setActivationPolicy lib “Cocoa” selector “setActivationPolicy:” (obj as ptr, val as integer)
declare function sharedApplication lib “Cocoa” selector “sharedApplication” (obj as ptr) as ptr
declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr

const NSApplicationActivationPolicyRegular=0

dim sa As ptr=sharedApplication(NSClassFromString(“NSApplication”))

setActivationPolicy(sa,NSApplicationActivationPolicyRegular)
[/code]

Unless the user previously set the preference to hide the icon.

The code above just makes the dock icon pop back in. You can hide it via code also, but it makes it tricky trying get the app active again… better to just relaunch when the option is selected.

[quote=103962:@jim mckay]I’ve done it by setting the NSUIElelment value in the plist and then on launch call

[code] declare sub setActivationPolicy lib “Cocoa” selector “setActivationPolicy:” (obj as ptr, val as integer)
declare function sharedApplication lib “Cocoa” selector “sharedApplication” (obj as ptr) as ptr
declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr

const NSApplicationActivationPolicyRegular=0

dim sa As ptr=sharedApplication(NSClassFromString(“NSApplication”))

setActivationPolicy(sa,NSApplicationActivationPolicyRegular)
[/code]

Unless the user previously set the preference to hide the icon.

The code above just makes the dock icon pop back in. You can hide it via code also, but it makes it tricky trying get the app active again… better to just relaunch when the option is selected.[/quote]

Thank you Jim.

After re-reading your post because Jim quoted it, I’m not sure that it’s a good idea.

Instead I would advise re-considering your UI. It’s obvious that some of the App Reviewers freak out when they come across something that isn’t the norm… As do regular users also, my wife is really great when testing UI as while she’s not a geek, if somethings not quite right and causes her repeated frustration, it’s time to think again.

I would start by thinking about the life span of your application. Is this an app that a user fires up to do a bit of work and then quite once they’re done? Or is it an app that stays in the background awaiting user input?

These are just suggestions, so I won’t be offended if you think I’m talking out of my arse.

[quote=104103:@Sam Rowlands]I would start by thinking about the life span of your application. Is this an app that a user fires up to do a bit of work and then quite once they’re done? Or is it an app that stays in the background awaiting user input?

[/quote]

This app displays a small icon-like window in the lower left corner of the screen. When clicked, it displays a window where the user can perform tasks with folders and programs. It is intended to be lauched upon startup, and serve throughout the session when called.

Nothing really prevents it to have a dock icon and a menu, except the dock icon and the icon-like window will appear as redundant. But indeed, I fear the psycho-rigid reviewer who will reject the app for not complying to Apple guidelines upon launch. I have not been able to try Jim’s code yet, but if the user can decide for himself to hide the dock icon, then maybe the reviewer could let it pass. At any rate, I am preparing for all contingencies : I will write the app as I think it should behave, and send it up. If it gets rejected, I will display dock icon and menu. Then the user will be able to click on either the small window or the dock icon, and use the menus if they feel like it.

Jim solution could be the way to reconcile both : upon first launch, the app displays both icon and menu. Then the user can decide through preferences to hide them, and next time the app is launched, menu and icon are hidden.

Yep, this is pretty much what Dash does (which is in the Mac App Store).

That’s what SimpleKeys does (also in the MAS), Only difference is I bring the Dock Icon back when the app is frontmost and hide it again when deactivated (per user preference) and the StatusItem has to be visible to hide the Dock Icon to ensure the user doesn’t end up with no way to quit the app. Never had a complaint from the reviewers.

Jim,
how do you bring a dock icon BACK??

In the LR, I can only see Reset and Update?
Or does RESET also unhide an app icon?

NSApplicationActivationPolicyRegular brings it back if hidden, while NSApplicationActivationPolicyProhibited+NSApplicationActivationPolicyAccessory will hide it… only problem is that then you’re in background only mode with no UI allowed (any visible windows are then hidden, aside from NSStausItem)

Their values are 1+2, I don’t remember which is which offhand, but setting NSApplicationActivationPolicyAccessory SHOULD hide the Icon per Apple’s docs, but has never worked for me by itself…

Do you mean that the following code should* re-display a hidden dock icon:

NSApplicationActivationPolicyRegular = 1

And that the following code should re-hide it:

NSApplicationActivationPolicyProhibited = 2 NSApplicationActivationPolicyAccessory = 2

setActivationPolicy(sa,NSApplicationActivationPolicyRegular) //bring it back <–normal mode

setActivationPolicy(sa,NSApplicationActivationPolicyProhibited+NSApplicationActivationPolicyAccessory) //hide it <–background only mode

Being a Xojo only person - is that valid Xojo code which could for example be placed in a button, or would that need to be converted somehow into Xojo code?

Sorry for the ignorance - but I do not use anything else apart from Xojo :slight_smile:

It’s valid Xojo code, but goes along with the code I posted above…

[code]Sub hideShowIcon(IconVisible as Boolean)
declare sub setActivationPolicy lib “Cocoa” selector “setActivationPolicy:” (obj as ptr, val as integer)
declare function sharedApplication lib “Cocoa” selector “sharedApplication” (obj as ptr) as ptr
declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr

const NSApplicationActivationPolicyRegular=0
const NSApplicationActivationPolicyAccessory=1
const NSApplicationActivationPolicyProhibited=2

dim sa As ptr=sharedApplication(NSClassFromString(“NSApplication”))

if IconVisible then
setActivationPolicy(sa,NSApplicationActivationPolicyRegular) //bring it back <–normal mode
else
setActivationPolicy(sa,NSApplicationActivationPolicyProhibited) //hide it <–background only mode
end if

End Sub

[/code]

Now that I’m re-testing it, it seems NSApplicationActivationPolicyProhibited will put it back in background mode… not sure why NSApplicationActivationPolicyAccessory does nothing. This does require the LSUIElement or LUBackgroundOnly key be set to 1 in your app’s info.plist.