Checking whether spoken commands are enabled? - objective-c

Is there a way to check whether the user has enabled speech recognition (spoken commands) in System Preferences? (Mac OS X). If the user has it enabled, I would like to support additional speech commands. Unfortunately there isn't any method in NSSpeechRecognizer to check this and I can't seem to find any Carbon functions to check it either.
One of the problem is that the round Speech Commands window (the one with a microphone on it) seems to appear intermittently whenever I instantiate NSSpeechRecognizer. Also it often freezes my app for about half a second or so while the object is created (probably it's starting up the speech recognition service).
In essence, if the speech recognizer isn't already running and being used, I don't want to start it up. But if the user actively uses the speech recognizer, I would like to provide additional support for it.
Thanks in advance.

I don't know the public API either; but the round mic window is controlled by SpeakableItems.app, at least on OS X 10.6. You can check the process list and/or the running applications list to see if it's there.

As inspired by #Yuji's answer, looks like the only way is to check whether the speech recognition server is running or not. Here is the code snippet, in case anyone also need it.
+(BOOL) speakableItemsEnabled {
NSString* speechServerBundleName = #"com.apple.speech.recognitionserver";
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:speechServerBundleName];
NSRunningApplication* speechServerApp = [apps lastObject];
return speechServerApp && !speechServerApp.terminated;
}
Hopefully this doesn't break in 10.7 "Lion".

Related

How to add double tap detection to sample app gatt_sensordata_app?

I am developing an Android app that gets data from Movesense using the GATT profile from the sample app GATT Sensor Data App here.
I followed the tutorial available here. Building the app and getting the DFU worked fine. I can get IMU, HR and temperature data with no issues.
Now I'd like add a tap detection feature to my app. I understand that I have to subscribe to 'System/States', but first I need to be able to receive the system state data.
I understand that I need a modified DFU for that, but I don't understand what changes I should make in which files of the gatt_sensordata_app before rebuilding and generating the new DFU.
What changes should I make in order to broadcast /System/State data?
(I usually just deal with Android so apologies for the very basic question.)
I tried adding #include "system_states/resources.h" to GATTSensorDataClient.cpp but I don't know how to continue.
The normal data straming in the gatt_sensordata_app uses the sbem-encoding code that the build process generates when building the firmware. However /System/States is not among the paths that the code can serialize. Therefore the only possibility is to implement the States-support to the firmware.
Easiest way is to do as follows:
In your python app call data subscription with "/System/States/3" (3 == DOUBLE_TAP)
Add a special case to the switch in onNotify which matches the localResourceId to the WB_RES::LOCAL::SYSTEM_STATES_STATEID::LID
In that handler, return the data the way you want. Easiest is to copy paste the "default" handler but replace the code between getSbemLength() & writeToSbemBuffer(...) calls with your own serialization code
Full disclosure: I work for the Movesense team

What exactly should I pass to -[NSApp activateIgnoringOtherApps:] to get my application to start "naturally" in comparison to most other OS X apps?

When I learned how to start NSApplications on my own, the code I used (based on here and here) did
[NSApp activateIgnoringOtherApps:YES];
which forces the app to the front at startup.
I'd like to know what most other apps do. I want to be able to run programs both directly from the binary and from an app bundle, and I'm not using Xcode to build this (raw building). So I'd rather this act naturally, so to speak.
The docs do say Finder issues NO, but... why Finder? Isn't this a method that's run from within the process, not outside? (I'm not in control of the choice.) And what about the Dock and other possible entry points?
I even went so far as to disassemble 10.8's NSApplicationMain() to see what it did, but as far as I can tell from the 32-bit version, unless this "light launch" thing issues this selector, this selector is never called.
Is there an answer to this question? Thanks... and sorry if this is confusing; I tried to word it as clearly as possible.
Apps normally do not call -activateIgnoringOtherApps: at all. And, generally speaking, shouldn't. Certainly, it wouldn't be in NSApplicationMain(), which is too early and fairly distantly related to actual app start-up.
Apps are normally launched by Launch Services (which is what is used by the Finder, the Dock, and /usr/bin/open, as well as any other app that might open yours or a document which yours handles). Roughly what happens is that Launch Services deactivates the app which called it to open something else and then, in the launched app, Cocoa's internals do something like (but not necessarily identical to) [NSApp activateIgnoringOtherApps:NO]. In this way, the launched app only activates if nothing else was activated in the interval between those two events. If that interval is long (because something was slow) and the user switched to something else in the meantime, you don't want to steal focus from whatever they switched to.
You should only call [NSApp activateIgnoringOtherApps:YES] in response to a user request to activate your app in a context which won't include the automatic deactivation of the current app by Launch Services. For example, if you have a command-line program which transforms itself into a GUI app (using -[NSApplication setActivationPolicy:] or the deprecated TransformProcessType()), then the user running that tool means they want it active. But Terminal is active and won't be deactivated spontaneously just by virtue of having run your program. So, the program has to steal focus.
If your program is a bundled app, then running it from the command line should be done with /usr/bin/open rather than directly executing the executable inside the bundle. Then, you don't need to call -activateIgnoringOtherApps: at all and the question of what value to pass is moot.

Is there any private api to monitor network traffic on iPhone?

I need to implement an app that monitors inbound/outbound connections by different apps on iPhone. my app is going to run in background using apple's background multitasking feature for voip and navigators.
I can use private api as my client doesn't need this app on appstore.
Thanks.
I got through this.
I didn't need any private Api to get information of inbound/outbound active connections.
Its just you need to know basic C programming and some patience.
I wrote to apple dev forums regarding this,and got response as-
From my perspective most of what I have to say about this issue is covered in the post referenced below.
<https://devforums.apple.com/message/748272#748272>>
The way to make progress on this is to:
o grab the relevant headers from the Mac OS X SDK
o look at the Darwin source for netstat to see how the pieces fit together
WARNING: There are serious compatibility risks associated with shipping an app that uses this technique; it's fine to use this for debugging and so on, but I recommend against shipping code like this to end users.
What I did step by step is -
1)downloaded code of netstat from BSD opensource -
2)add this to your new iphone project.
3)see,some header files are not present in ios sdk so you need take it copied from opensource.apple.com and add those in your iphone sdk at relevant path under-
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/include
My xcode version is 4.5.2. so this is path relevent to my xcode. you can have different path according to versions of xcodes.Anyway. and remember to add those headers in both iosSdk & iOSSimulatorSdk both so that code will work on device as well as on simulator.
4)you may find some minor errors in netstat code relating not finding definitions of some structures in header files.e.g " struct xunpcb64 " .dont wory. definitions are present there.you need to comment some "#if !TARGET_OS_EMBEDDED" #else in those header files so that ios sdk can reach in those if condition and access the definition.(need some try and error.be patient.)
5)finally you will be abe to compile your code.Cheers!!
In case you haven't seen this already, I have used it successfully on my iPhone.
https://developer.apple.com/library/ios/ipad/#qa/qa1176/_index.html
I realize it is not exactly what you want.
Generally, I agree with Suneet. All you need is network sniffer.
You can try to do partial port of WireShark (it's open source and it works on MacOS) to iOS. Both iOS and OS X share most part of the kernel, so if it's not explicitly prohibited on iOS, it should work for you.
WireShark is quite big product, so you may be intersted to look for another open source network sniffer which work on OS X.

Check if a process is a windowed process in OSX

Given the PID of a process, how can I check if it's a windowed process? I am looking for a solution on OSX.
Objective-C/ C solutions are wanted.
I am on OSX Mountain Lion.
I am defining a windowed process as a process that can be seen when the "Windowed Processes" tab is selected in activity monitor. http://cl.ly/FeXR
[NSWorkspace runningApplications]
This returns all the user applications in a NSArray as instances of NSRunningApplication which has a property processIdentifier.
Or you can use runningApplicationWithProcessIdentifier: directly to get the application with a specified PID.
Here is the sample code: http://developer.apple.com/library/Mac/#samplecode/AppList/Introduction/Intro.html
Through the activationPolicy property of the NSRunningApplication you could get the Windowed state. I modified the AppList code to make it show only the windowed applications as shown below. This matches what the activity monitor shows.
In particular, you are looking for the NSApplicationActivationPolicyRegular.
Note the restrictions however. This only works for user owned processes.
All other methods are deprecated and may not work in future. Methods like GetBSDProcessList and Carbon's GetProcessInformation are not recommended anymore.

Programmatically turn off an individual monitor

Is there an API or way to programmatically turn off an individual, external monitor via Objective-C on a Mac?
I'm looking to write a small menubar application that can control a secondary display (without a physical power button), but still keep the primary monitor in use.
Hunting around the API documentation, I can't seem to find anything, other then reading states. So hoping someone else might have an idea.
You can't "programmatically turn off an individual monitor", it's not physically possible. The most you can do is tell the OS to not use the monitor, but I don't think you can change system-wide settings like that, especially not at the level you're working on (Obj-C).
Looking at the Core Graphics API mentioned in #Halley's comment, try starting with the CGBeginDisplayConfiguration method and see if you can set a display configuration to your liking.
EDIT: Alternatively, you could also use CGDisplayCapture(displayID), which by default fills the captured display with black. You can then
call CGDisplayRelease(displayID) when you want to turn it back on.
It seems to be possible to sleep display so by I/O Kit:
https://web.archive.org/web/20161106204726/http://www.cocoabuilder.com/archive/cocoa/191807-sleep-display.html
http://explanatorygap.net/2009/01/31/a-screensaver-to-send-your-display-to-sleep/
But I am not sure whether it can control single monitors.