Skip to content

Instantly share code, notes, and snippets.

@atr000
Created May 26, 2010 11:06
Show Gist options
  • Save atr000/414349 to your computer and use it in GitHub Desktop.
Save atr000/414349 to your computer and use it in GitHub Desktop.
ScreenFrame.m
/*
This is a free command line utility made by ief2.
You are allowed to use it for personal use, publishing
or usage in self-made applications.
Developer's Site:
http://developerief2.site11.com
*/
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// -s screen number
// -v visible frame
/* ========== ARGUMENTS ========== */
// retreive arguments
int screenNumber = [[NSUserDefaults standardUserDefaults] integerForKey:@"s"];
BOOL visibleFlag = [[NSUserDefaults standardUserDefaults] boolForKey:@"v"];
// check arguments
if(!screenNumber) {
printf("Screen number was not defined (-s)\n");
return 1;
} else if(screenNumber > [[NSScreen screens] count]) {
printf("Screen does not exist at given index\n");
return 1;
}
/* ========== GET FRAME ========== */
NSRect screenFrame;
screenNumber -= 1;
if(visibleFlag == YES)
screenFrame = [[[NSScreen screens] objectAtIndex:screenNumber] visibleFrame];
else
screenFrame = [[[NSScreen screens] objectAtIndex:screenNumber] frame];
/* ========== RETURN RESULT ========== */
printf("x:%i y:%i width:%i height:%i\n",
(int)screenFrame.origin.x,
(int)screenFrame.origin.y,
(int)screenFrame.size.width,
(int)screenFrame.size.height);
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment