Skip to content

Commit

Permalink
Add systemIdleTime.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-h committed Apr 18, 2014
1 parent 2a090da commit b2ce700
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MacGap/Classes/Commands/App.h
Expand Up @@ -17,5 +17,5 @@
- (void) beep;
- (void) bounce;
- (void) setCustomUserAgent:(NSString *)userAgentString;

- (NSNumber*) systemIdleTime;
@end
17 changes: 17 additions & 0 deletions MacGap/Classes/Commands/App.m
Expand Up @@ -83,6 +83,21 @@ - (void) receiveActivateNotification:(NSNotification*)notification{
}
}




/*
To get the elapsed time since the previous input event—keyboard, mouse, or tablet—specify kCGAnyInputEventType.
*/
- (NSNumber*)systemIdleTime {
CFTimeInterval timeSinceLastEvent = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);

return [NSNumber numberWithDouble:timeSinceLastEvent];
}




+ (NSString*) webScriptNameForSelector:(SEL)selector
{
id result = nil;
Expand All @@ -93,6 +108,8 @@ + (NSString*) webScriptNameForSelector:(SEL)selector
result = @"launch";
} else if (selector == @selector(setCustomUserAgent:)) {
result = @"setCustomUserAgent";
} else if (selector == @selector(systemIdleTime)) {
result = @"systemIdleTime";
}

return result;
Expand Down
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,7 @@ MacGap exposes an object called `macgap` inside JavaScript. You can use it to al

App:

```js
// Quit application
macgap.app.terminate();

Expand Down Expand Up @@ -46,6 +47,12 @@ App:
// Set a custom user agent string
macgap.app.setCustomUserAgent('new user agent string');

// Get the system idle time. This example outputs the idle time to the console once per second.
window.setInterval(function(){
console.log( macgap.app.systemIdleTime() );
}, 1000);


Clipboard:

// copy text to clipboard
Expand Down

0 comments on commit b2ce700

Please sign in to comment.