I want to write an app for Mac OS X. The app/utility would act according to preset schedule. I will have different time intervals at which I want this app to show a certain image in full screen regarding if there are other apps running at the time.
The real question is how to check this time interval in the background and bring this app in-front and enter full screen. I know how to go full screen, but I am stuck at bringing this app in-front of all other apps.
To schedule a method to be called after an interval, just use NSTimer and one of its +scheduledTimer... methods.
To force your application to be active, call [NSApp activateIgnoringOtherApps:YES].
If you want your window to appear above absolutely everything, including the screensaver, set its level to NSScreenSaverWindowLevel + 1.
The only solution that comes immediately to mind is use AppleScript, e.g. if you execute the following AppleScript from within your app:
tell application "MyBackgroundApp"
activate
end tell
There is an Apple Tech Note with sample code for sending AppleScript from a Cocoa app using NSAppleScript.
How to force Mac window to foreground?
Related
I'm trying to figure out how to prevent users of my app from snapping a screenshot of any of my app's windows. I'm mainly concerned with users automating screenshots using /usr/sbin/screencapture with cron. At first I thought there was no way to prevent it but then I discovered that there are some apps that are doing something that causes the screenshot to be all black or the color of the desktop. If I could pull that off I would be golden. I've seen other posts that touch on the subject but nothing that actually works in my situation. I'm running catalina. Any and all insights would be greatly appreciated.
Use NSWindowSharingNone of sharingType property on NSWindow
setSharingType: specifies whether the window content can be read
and/or written from another process. The default sharing type is
NSWindowSharingReadOnly, which means other processes can read the
window content (eg. for window capture) but cannot modify it. If you
set your window sharing type to NSWindowSharingNone, so that the
content cannot be captured, your window will also not be able to
participate in a number of system services, so this setting should be
used with caution. If you set your window sharing type to
NSWindowSharingReadWrite, other processes can both read and modify the
window content.
#property NSWindowSharingType sharingType API_AVAILABLE(macos(10.5));
Trying to figure out how to write an application that prevents a user from using any other application during a (user set) time period. Sort of like a "modal" application.
Have given up trying to disable the internet connection, so the next best thing would be to make the application itself modal, i.e. only the application has focus (in full screen mode) for a set period of time, with the user unable to switch applications or exit full screen.
Is this possible using Xcode and Cocoa?
Any hints appreciated!
Thanks,
John
What you want is called kiosk mode.
is in shell (Mac OS X Lion) a way how run program on specify position on screen?
I want to run two programs and specify their position on screen so one window will be next to another and they will be centered on screen.
You could try to hack something together using AppleScript. This link shows you how to set the window geometry of a certain application. The problem might be in actually talking to the processes that you just started. This SO question deals a bit with using the process id to talk to an app using AppleScript.
I need my application to launch in a specific display (assuming there's more than one display) and go to full screen. The app itself is a Flash app, but I can write a native executable for the mac to launch it, I just don't know how to dictate which display it opens in. This is a fairly simple thing to do in Windows, I was hoping there's a mac analog.
[EDIT] poking around COCOA app development seems to suggest that the NSScreen object is the way to go here.
Take a look at the documentation for CGDisplayBounds, CGDisplayCapture and CGGetOnlineDisplayList. With these functions you can get the list of displays, find the display bounds to create your window. And even capture the display so only your app can use it.
I would like to show the user a splash screen (a picture) while my Cocoa-based application launches. How would this be possible?
First thanks a lot. because my app running for a while time , so I want to show a splash before app running . Now if I show a window inside with a image , after that how to run the app? How to make sure that the app running after the splash showing ? How to do to get the sequence ?
First Thank you very much. And I show the window in applicationWillFinishLaunching method use orderFront,then hide it in applicationDidFinishLaunching: use orderOut,Now I found that the mainWindow not to show and the app terminate ,why ? How to do to resolute this question? Thanks!
Although Peter's answer is ultimately correct (you should rewrite your app to launch faster), sometimes that's not a practical option. For example loading code later in the application may take too long (e.g. a data acquisition application), forcing it to be loaded at startup. If you decide that you want to show a splash screen, the easiest way is to show it in the application delegate's applicationWillFinishLaunching: method. Create a splash window in your applications MainMenu.nib and add an outlet to your app delegate referencing that window. You can then put the window onscreen in applicationWillFinishLaunching: and hide it in applicationDidFinishLaunching:. Note that the main thread's NSRunLoop is not iterating during this time, so if you want to update the splash screen (with status, a progress bar, or such), you'll need to manage those redraw events yourself.
Again, think very hard about whether the long startup is necessary. If it is, showing a splash screen with a progess indicator is the minimum that you owe your users.
Why do you hate your users?
Seriously, don't do this. Don't make your users wait to use your app. Make your app launch quickly instead.
(And just in case you insist on an answer: Show a window with the image in it, then hide the window when you feel the user has waited long enough.)
Just put up a window with the image and close it when you are done with your launch initialization.
Barry's answer above does not seem to work for document-based apps. Showing a splash window within applicationWillFinishLaunching: interferes with the startup sequence of the app such that the document window isn't created. I've uploaded an example project here. In applicationWillFinishLaunching:, comment out [_splashWindow orderFront:self ] and the document window will come up.