Title: Bring NSRunAlertPanel Dialogue to Front in Background Process
Tags: cocoa;nsalert
Question: If you call
NSRunAlertPanel()
from a background process in Cocoa, the dialogue does not come to the front and instead stays behind other windows.  This post shows that you can bring the dialogue to the front if you convert the process to a foreground process.  If you keep the process a background process, however, is there any way to achieve this behavior?


Here is another answer: What are you trying to do?  Background processes can still display UI and bring themselves to the front without using TransformProcessType; just make sure you are a LSUIElement, not LSBackgroundOnly (or the deprecated NS* equivalents).  The only reason you typically need to use TransformProcessType is if you want a Dock icon or menu bar.
Comment for this answer: You need to bring your app to the front then: [NSApp activateIgnoringOtherApps: YES];
Comment for this answer: I have a program running that has a presence in the menu bar.  When the program starts running, I want it to throw up a dialogue that asks the user whether or not they want to set the program to parkerlaura@example.com.  Right now calling `NSRunAlertPanel()` the dialogue comes up but is often hidden behind other windows.  How would I keep my program running with only a menu bar presence but make the dialogue come to the front of all the windows?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:05/05/10', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<cocoa><nsalert>', 'Title': 'Bring NSRunAlertPanel Dialogue to Front in Background Process', 'ViewCount': 654, 'id': 2775833, 'user_AboutMe': '<p>iOS developer at Airbnb.\nPrevious: Co-Creator and CTO at <a href="http://getcalpal.com" rel="nofollow noreferrer">CalPal</a></p>\n', 'user_AccountId': 105180.0, 'user_DisplayName': 'mon4goos', 'user_Reputation': 1559.0, 'user_Views': 82.0, 'user_id': 280789.0}}