Detect sending message - winapi

I want to send message(i-message) from my MacBook desktop to my cell phone when I close the lid and the desktop goes to sleep mode.
However my desktop goes to sleep mode faster than it sends message after I close the lid.
Is it possible to detect sending message faster or make the sending time shorter?
I'm using applescript, but will take any suggestions in any language, because sending message is for my university subjects and other languages will be useful for doing same thing on other microsoft desktops.

You can use SleepWatcher http://www.bernhard-baehr.de/ in command line to detect sleep and perform a command line action
I just tried to send SMS to my phone using nexmo and got it after closed the lid
airair2:sleepwatcher_2.2 bis$ ./sleepwatcher -s 'curl "https://rest.nexmo.com/sms/json?api_key=key&api_secret=secret&from4249996003&to=14245555555&text=Alarm%21+Temperature+inside+the+car+is+critical+%2895F%29"'
{"message-count":"1","messages":[{"to":"14242179430","message-id":"020000004477EA13","status":"0","remaining-balance":"14.06670000","message-price":"0.00480000","network":"310260"}]}

Related

Windows execute command before sleep / on power button press

I want my power button to send a HTTP request before going to sleep.
I already set a task to execute with trigger System/Kernel-Power/42 but the task executes after the next wake rather than before sleep.
Also autohotkey doesn't seem to log the power button neither does a windows trigger.
Is it possible to delay windows sleep? I could not find a way to do that.
Thanks
So it's not a real answer but I came up with a solution:
If the wifi hotspot is turned on (I need it anyways) while my pc goes into sleep mode, it sends a System/Kernel-Power/59 and turns the monitor off.
I now have a task that listens for this and executes what I want, then turns the hotspot off and then turns the pc into sleep mode.

Getting output of `pmset -g ps` to to trigger an email via Mail.app when output includes "UPS Power"

I've just gotten a UPS and would want notification emails whenever the UPS kicks in. I've connected the UPS via USB so OS X can monitor it via Energy Saver, but there are no other options for notifications.
I've tried installing apcupsd, but am not able to install it due to compatibility issues with OS X 10.11.1
In an effort to find a simple workaround in absence of apcupsd to accomplish this, I am looking at using pmset -g ps to indicate the current power status since it gives an string output indicating status as "AC Power" or "UPS Power"
I want an email to be sent whenever the output of pmset -g ps contains "UPS Power". Not really sure if I need to pipe the output as a file or set it to the clipboard, which then can be read by the terminal in order to trigger an email via Mail.app if it contains that particular string, or if there is a simpler method via Automator to accomplish this.
Thank You!

Windows phone app that detects call, SMS and alarms and sends notification to PC

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

Windows 7.1 SDK - Timing a call

I currently have a "dumbphone", but I'm trying to make an app that'll time and store the call duration of incoming calls for windows 7.1 ("7.5") phones, for the user scheduling purposes.
However, after extensive searching and googling, with topics like this one:
Windows Phone 7 - How to calculate call duration or termination
it seems that the Windows 7/7.1 SDK does not allow access to recognizing when a call is coming in. I've read about obscure and unobscure, but that this wouldn't be a good idea since it would start the timer anytime the UI hides the program, not just calls.
I've thought that maybe I could just pull the call duration or the start/end time from the call history, but windows 7 SDK doesn't support that either it seems.
So I decided to seek help. Is there a way to make this work? Is there some clever way to recognize when a call is incoming and stopped? Or some clever way to pull call times/durations? Or maybe a way to detect when the user presses that "accept incoming call" button? Or maybe a way to single out when a call is obscuring the UI?
Any help would be greatly appreciated. Thank you
Due to security reasons your application does not have any kind of accsess to call history ect. So you are in a sendbox and you don't know nothing about phone calls.
From the Windows Phone SDK, there is no way to achieve this!
The only thing I can think of is that when a call comes, the current app gets notified that is now Obscured because a new screen is now on top of it (the caller ID screen), and will get notified when it gets back to focus.
But the truth is that this happens even if a SMS message notification pops on the screen and the user taps to read it, or some app gets a notification pushed...

Detect if Windows Phone 7 is connected to desktop Zune software

I've been working on a Windows Phone 7 app for a few months now and have a collection of useful detection flags that are used to test for things like if the code is running in the emulator, on a background/foreground thread, or at design time. (see full list here)
I now want to add a new flag that will check if the phone is connected to a desktop using a USB cable to prevent issues that users are reporting. There are certain operations that are blocked while the phone is connected to the Zune software, for example you cannot use the camera (it will just open and then immediately close with e.TaskResult == Microsoft.Phone.Tasks.TaskResult.Cancel). This causes my app to think that the user canceled the photo, which the user miss-interprets as the app not working correctly.
I'd like to detect when the phone is connected to the Zune software and provide a message saying the camera will not work until they disconnect it. Is there any way to do this?
Gabor Dolhai has a full blog post on Zune Detection and Network Awareness, which uses a combiantion of NetworkInterfaceType detection and the NetworkAddressChangeed event.
Testing for NetworkInterfaceType being Ethernet gets you close, but not quite there - as this isn't sensitive to the status of Zune vs WPConnect for the connection. Also, reading NetworkInterfaceType also can prove to be less than a walk in the park.
Handling the resulting exception seems to be the reliable method, however the exception does appear to vary between some media APIs, so keep an eye out for that.
After reviewing the answers from Mike and Derek, I Decided to go with a simple timer to detect when the CameraCaptureTask returns faster than expected. This is done by adding the following right before the call to start the capture task:
State["CameraCaptureStart"] = DateTime.Now;//Save start time to detect fast cancel from zune software
Then when the capture finishes you can detect if it returned too fast:
//Detect if task returned too fast
if (State.ContainsKey("CameraCaptureStart"))
{
DateTime dtStart = (DateTime)State["CameraCaptureStart"];
TimeSpan ts = DateTime.Now - dtStart;
if (ts < TimeSpan.FromSeconds(3))
{
MessageBox.Show("Error: Camera does not work while phone is connected to the Zune software.");
}
}
In my testing the fastest I could load the camera, take a picure, and push the accept button was around 5-6 seconds, where as the Zune software would automatic cancel and return in around 2.5 seconds.
This approach is simple and works well for my situation, however you should be aware that the error message will also be displayed if the user presses the back button before the 3 second timeout has elapsed.

Resources