How to hide fullscreen apps in MacOS programmatically - objective-c

I'm trying to make an app that would hide other windows/apps with a certain interval, but I'm stuck with hiding fullscreen app windows using NSWorkspace and NSRunningApplication classes.
Is there any way to exit fullscreen mode programmatically using public APIs? If not, what private APIs I need to look at to achieve this task?

Assuming you can get around sandboxing, you can use AppleScript to tell System Events to tell the process in question to set its attribute "AXFullScreen" of window 1 to false.

Related

Is there a way to programatically toggle vibrate?

In objective-c for iOS dev, is there any way to programatically toggle the vibrate on/off? And also to check its current state?
If there is, where might I find it in documentation? I've looked and cannot find it so maybe it's not possible?
Edit: I don't mean to make the phone vibrate. What I mean is that when the phone is on silent there is a toggle to have vibration on/off. Can this be controlled programatically?
No you can't.
This is a system defined property (that your user can access from Settings).
None of the iOS APIs allow such kind of control.

How can I detect/observe when third party app launches a full screen process?

I would like to build a helper app for gamers, and to build some extra functionality I would like to observe/time certain third party games behaviors, more specifically when the game actually launches the full screen process.
For example: my app is a system tray app, the game has a "launcher" app with lobby and menu screens. Once the game launches the extra process, usually OS X will switch resolutions (optionally) and my App would be notified somehow. Then I can start a timer. Once game match finishes, either the process is closed, or the game is not full screen anymore, my app gets a second notification and I can stop the timer.
Are there official Apple APIs that provide any way to observe/poll for the app going full screen and/or launch additional windows that I can reliably assume it's the actual game screen?
I doubt you're going to find a completely comprehensive solution. There are many ways for apps to achieve a full-screen experience and most don't provide a notification about that fact.
A full-screen app can modify the presentationOptions of NSApplication to hide the Dock and menu bar. Another app can use key-value observing to monitor its application object's currentSystemPresentationOptions property, which will reflect the current system status.
A full-screen app can capture the displays (although Apple discourages this technique). You can try to detect this by calling CGDisplayIsCaptured(), although it's been deprecated since 10.9 with no replacement. It may be possible that, if you register a callback with CGDisplayRegisterReconfigurationCallback(), you'll get called when something captures the display. However, capturing the display is sort of about preventing other processes from noticing such changes, so maybe not. In that case, you'd have to poll. You might also poll for the current display mode; changing the mode is the primary reason why a game would capture the display in the first place.
A full-screen game could also just create a borderless window the size of the screen and set its window level to be in front of the Dock and menu bar (and other apps' windows). There's not really a notification about this. You could detect it using the CGWindowList API, but you would have to poll. For example, you could call CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID) and iterate through the dictionaries looking for one the size of the screen and at a window level above kCGStatusWindowLevel.
(You might be able to use the Accessibility API to get a notification when the frontmost window changes, so you'd only have to poll when that happens.)
You cannot observe a notification if there is none. So firstly you need to know if the app you want to observe is actually sending a notification that is observable. You cannot 'hook' into other apps without their planned consent.

How do you hide the menu bar in a Cocoa app?

How do you programmatically hide the menu bar in a cocoa app? I would like to make full use of the screen area.
There are two good ways I know of to do this.
1
In Cocoa, you can call the NSMenu class method setMenuBarVisible: to show or hide the menu bar.
As of this writing, the documentation for the NSMenu class does not tell you the following additional information.
The menu bar will only be hidden for the app that calls this method.
The Dock will also be hidden at the same time.
(This is true at least in 10.9 and I have not tested any other versions.)
This is useful when you want to use an app in a full screen way where you have a cover window, a borderless window the size of the screen.
The nice feature of this (as opposed to playing with LSUIElement settings) is that your app can continue to be in the application switcher cycling, as well as visible in the Dock when other apps are active.
This allows users to still activate a full screen app through the Dock or application switcher.
That means you can still use your app's Dock menu to access a preferences window for your app or other features.
This is incredibly convenient if your app is indeed a full screen cover window that runs at a window level higher than other apps, but you still want to make preferences and the ability to quit your app available, and you want your app's visual functionality available when other apps are active.
2
Another option is via NSApplication's method setPresentationOptions: with the arguments from NSApplicationPresentationOptions enum, such as option NSApplicationPresentationHideMenuBar
With this approach be very wary of reading the documentation, although it gives you additional options, and is still app-specific only, you need to know that some of the options are mutually exclusive. There are rules you must follow, or you get nothing but exceptions spewed to the console.
3 There is a 3rd and crappy option. If you have a helper app that is a daemon, you can use it to change your app's LSUIElement state and basically relaunch your app. It's dumb and it takes you out of the app switcher completely, which is great if you really are writing something that should not be there, but that is rare.
There is also the NSView enterFullScreenMode:withOptions: method, although most apps for which that would be appropriate prior to 10.7 should probably use the modern full-screen-window API on 10.7 and later.

How to make an app without titlebar?

I'm quite new to developing on the Mac, I've only done iPhone programming until now. I'm trying to make an app that doesn't have a titlebar. I'd still like to allow the user to move the window around by clicking anywhere within the window and dragging. Is this possible, and if so, how can I get started on something like this? Thanks!
You could make it a borderless window.
[myWindow setStyleMask:NSBorderlessWindowMask];

find out fullscreen button in youtube embedded player programatically

I wanted to know that is there any way to find out programatically the fullscreen button that is added on the youtube embedded player so that I can call an action on its touchupInsideEvent.
Please help.
Thanks in advance.
Shruti
In general, it's not possible to intercept events like that into the flash player, unless the SWF has some sort of an API for that purpose.
A different way to approach the problem is to use the YouTube "chromeless" player. It's basically an embedded player with no user interface elements. You provide the controls, which can command the player via the Javascript interface. You can intercept a user request for maximize that way.
There's even a question on Stack Overflow that concerns with fullscreen functionality for Chromeless players.