Permalink
Browse files

[displays] grab screen resolutions with a objc app

  • Loading branch information...
1 parent b0e9ec7 commit 820c0c8242677dd4937ad32b9703967c7a15f042 @jgallen23 committed Jun 29, 2013
Showing with 78 additions and 6 deletions.
  1. +25 −3 Gruntfile.js
  2. +13 −3 lib/displays.applescript
  3. +40 −0 lib/screens.m
View
@@ -37,7 +37,7 @@ module.exports = function(grunt) {
}
},
alfred: {
- command: 'cp -v <%= compiledDist %> alfred-workflow/',
+ command: 'cp -v <%= compiledDist %> alfred-workflow/ && cp -v dist/screens alfred-workflow/',
options: {
stdout: true
}
@@ -47,6 +47,20 @@ module.exports = function(grunt) {
},
alfredZip: {
command: 'cd alfred-workflow/ && zip tmp * && mv tmp.zip ../dist/Layouts.alfredworkflow'
+ },
+ compileScreens: {
+ command: 'gcc -o dist/screens -Wall -std=c99 lib/screens.m -framework Foundation -framework AppKit -lobjc',
+ options: {
+ stdout: true,
+ stderr: true
+ }
+ },
+ runScreens: {
+ command: './dist/screens',
+ options: {
+ stdout: true,
+ stderr: true
+ }
}
},
watch: {
@@ -60,6 +74,13 @@ module.exports = function(grunt) {
'build',
'shell:test'
]
+ },
+ screens: {
+ files: 'lib/screens.m',
+ tasks: [
+ 'shell:compileScreens',
+ 'shell:runScreens'
+ ]
}
}
});
@@ -68,8 +89,9 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['build', 'alfred']);
- grunt.registerTask('build', ['concat', 'shell:compile']);
+ grunt.registerTask('build', ['concat', 'shell:compile', 'shell:compileScreens']);
grunt.registerTask('test', ['default', 'shell:test']);
grunt.registerTask('dev', ['watch:app']);
- grunt.registerTask('alfred', ['build', 'shell:alfred', 'shell:alfredVersion', 'shell:alfredZip']);
+ grunt.registerTask('alfred', ['shell:alfred', 'shell:alfredVersion', 'shell:alfredZip']);
+ grunt.registerTask('dev:screens', ['watch:screens']);
}
@@ -1,9 +1,18 @@
+on getScreens()
+ set tmp to do shell script "PWD"
+ set myPath to POSIX path of (path to me) as string
+ set dirname to (do shell script "dirname " & myPath) as string
+
+ set scrString to do shell script dirname & "/screens"
+ set scrRes to explode(",", scrString)
+
+ return scrRes
+end getScreens
+
on getDisplayBounds()
--TODO: multi monitor support
- tell application "Finder"
- set scrRes to bounds of window of desktop
- end tell
+ set scrRes to getScreens()
tell application "System Events"
tell dock preferences
set dockProperties to get properties
@@ -29,3 +38,4 @@ on getDisplayBounds()
return scrRes
end getDisplayBounds
+
View
@@ -0,0 +1,40 @@
+#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
+
+
+int main(int argc, const char * argv[]) {
+
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ //NSArray *screens = [NSScreen screens];
+
+ NSScreen *mainScreen = [NSScreen mainScreen];
+
+ NSRect rect = mainScreen.frame;
+ NSString *out = [NSString stringWithFormat:@"%1.0f,%1.0f,%1.0f,%1.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height];
+
+ const char *str = [out UTF8String];
+ printf(str);
+
+ // insert code here...
+ //NSLog(@"%@", [screens objectAtIndex:0]);
+
+ //for (NSScreen *screen in screens) {
+ //NSLog(@"%@", NSStringFromRect(screen.frame));
+ //NSString *str = NSStringFromRect(screen.frame);
+ //printf([str UTF8String]);
+ //}
+
+ //NSRunningApplication *activeApplication = nil;
+ //for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
+ //if (app.active) {
+ //activeApplication = app;
+ //break;
+ //}
+ //}
+
+ [pool drain];
+ return 0;
+}
+

0 comments on commit 820c0c8

Please sign in to comment.