I'm a Windows developer, but my team counterpart on the Mac side has asked me for help with an issue our Mac client has when the user wakes up his computer from hibernation.
I handle the wake up situation in our Windows client using the Windows WM_POWERBROADCAST message. This is a message that Windows sends to applications whenever there is a change in the power state of the hardware (on/off/suspend/resume).
Does OSX support a similar notification to tell running applications that the computer is suspending, resuming, or powering up or down?
TIA.
NSWorkspace has a bunch of notifications you can listen for.
Sorry, edited because the first post was completely wrong. NSWorkspace doesn't use the default notification center for notifications. This is copied mostly out of Apple's docs.
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:#selector(didWake:)
name:NSWorkspaceDidWakeNotification
object:nil];
Related
BACKGROUND INFORMATION:
I've been trying to detect a button click from Apple headphone. The headphone is connected to MacBook Pro that is running Windows. Its not virtual machine. It is running windows normally with a complete windows driver from Apple through Boot Camp.
The headphone is a standard Apple headphone consisted of three buttons: a volume up, volume down, middle buttons and a Mic.
When I am using Mac Os, If the volume up button is presses on the ear phone, Mac Os would increase its volume by one. It also decreases its volume when the voulume down button is pressed on the ear phone.
Standard ear/headphone uses three conductive pins to receive(L/R speakers only) signals while the apple version is using four conductive pins to receive(L/R speakers) and send(buttons) signals. This headphone was made for iPhone but I was surprised when it worked on Mac Os.
This made me believe that the MacBook Pro hardware is built to support this four conductive pins earphone. It works on Mac Os but NOT on Windows. My goal is to develop a tiny software that will allow the apple headphone to function on Windows running on Apple hardware.
I know how to increase Windows volume using C++ and Win32 API but I am stuck on the part where I actually have to detect the button click from the headphone.
QUESTION:
1) what ways can I detect the Input(button clicks) from the headphone?
It looks like this person here was able to read it. He only did it while running on Mac Os
Detect hardware headphone presses in mac
2) If I compile the code this person got working on Mac OS as a DLL file and then call the function while running Windows, will it work?
3) Do I need to make my own driver to get this to work?
4) The code below is from the link I posted above. What windows API function, class is equivelent to the follwoing Mac Os code below?
id array = [[DDHidDevice allDevices] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"productName == \"Apple Mikey HID Driver\""]];
DDHidDevice *mic = [array count] ? [array objectAtIndex:0] : nil;
// it isn't a keyboard
NSLog(#"%#", mic.primaryUsage);
assert(mic.usage==1 && mic.usagePage==12);
THINGS I'VE TRIED:
1) I tried using GetLastInputInfo() with LASTINPUTINFO from Windows API to sniff any hardware input but failed miserably. It worked on keyboard and mouse but nothing else.
2) I also tried to use RAWINPUTDEVICE to read a low level input from hardware but it only worked on keyboards, mouse and joystick input. It didn't detect the headphone button press.
I am running out of ideas. Anyone got any solution?
NOTE: This is not a duplicate question as I am asking how to do this on Windows not Mac.
How do I recognize in which host app my keyboard is running?
Basically, I want to change some things in my custom keyboard in specific apps
Maybe I can customize the keyboard traits to my use?
Thanks
This is not possible unless it is one of your own app, or you have some kind of collaboration with the running app.
A custom keyboard and a running app can communicate with Darwin notification. The running apps needs to broadcast the darwin notification, and keyboard needs to observe that. So if the developer is not already broadcasting it, then you can't identify it.
I'm trying to intercept when iTunes starts up on Mac OS X, so I can relaunch my application to work around few bugs in the iTunes Framework.
What I did is to temporarly disable the sandboxing of my application and listen to all NSDistributedNotificationCenter notifications in order to examine them and pick the ones I want.
What I found is that upon start iTunes apparently sends this event:
object: com.apple.iTunes.help name: HelpBookRegistrationDidChange userInfo: (null)
which seems rather unique but also doesn't give an exact clue it is related to a startup event only at 100%.
Does anyone know if this is safe way to intercept such event?
If so, once my app is sandboxed again I need to ask temporary permission to listen to this kind of event, how can I do that in code?
Do you believe scripting bridge can help in this case?
You don't need to disable sandboxing for this, just observe NSWorkspaceDidLaunchApplicationNotification in the notification center provided by NSWorkspace, not the distributed one.
You'll get an instance of NSRunningApplication in the user info of the notification, which you can use to determine whether the launched app was iTunes (use the bundleIdentifier property).
I am trying to develop an app for windows phone that will detect calls and send notification to PC through wifi. Similarly it will also send SMS that are received to PC and when an alarm goes off in phone, a notification will be sent to PC. How should I proceed about developing this app?
Thanks in advance.
There is no API exposed to allow you to spy on incoming calls or SMS in Windows Phone (like there was with Windows Mobile). The only option would be to build this as an OEM extension, but unless you work for HTC, Samsung or Nokia, this isn't going to be an option.
See it's not that you cannot but to some extent you can. Like you can use Obscured Event to detect call , lock screen etc. go through this msdn discussion for details
Detect lock and calls msdn
And as far as the alarm or the reminder is concerned you can go ahead and design a reminder system within your app. Limit is 50.
Obscured event Windows phone
I'm trying to get my mac app to do something whenever Safari is launched. The obvious way to detect Safari launch is by polling for running processes. Is there a better way to do this?
I was thinking there might be some API that I could use to register callbacks on, or perhaps there's a notification center event that I can observe.
You can add yourself to NSWorkspace's notification center as an observer for NSWorkspaceDidLaunchApplicationNotification. When you receive the notification, examine the instance of NSRunningApplication it provides (object in the notification's userInfo for the key NSWorkspaceApplicationKey) to determine if it was Safari that was launched.
Check the NSDistributedNotificationCenter and NSWorkspace classes.
The following post might be helpful: How to Listen For an Application Launch Event in Mac OS X?