Programmatically get screen size in Mac OS X










29















I am able to return the screen size using:



- (void) getScreenResolution 

NSArray *screenArray = [NSScreen screens];
NSScreen *mainScreen = [NSScreen mainScreen];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
NSRect screenRect = [screen visibleFrame];
NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main");

NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect));




Output:




Screen #0 (Main) Frame: 0, 4, 1344, 814




Is there a way to format 1344, 814 to 1344x814?




Edit:



This works perfectly:



- (NSString*) screenResolution 

NSRect screenRect;
NSArray *screenArray = [NSScreen screens];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
screenRect = [screen visibleFrame];


return [NSString stringWithFormat:@"%.1fx%.1f",screenRect.size.width, screenRect.size.height];










share|improve this question



















  • 2





    I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

    – Peter Hosey
    Feb 13 '11 at 6:44











  • Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

    – Vladimir Prudnikov
    Apr 3 '13 at 23:33











  • Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

    – adib
    Dec 9 '13 at 15:47












  • You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

    – WrightsCS
    Dec 9 '13 at 17:44















29















I am able to return the screen size using:



- (void) getScreenResolution 

NSArray *screenArray = [NSScreen screens];
NSScreen *mainScreen = [NSScreen mainScreen];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
NSRect screenRect = [screen visibleFrame];
NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main");

NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect));




Output:




Screen #0 (Main) Frame: 0, 4, 1344, 814




Is there a way to format 1344, 814 to 1344x814?




Edit:



This works perfectly:



- (NSString*) screenResolution 

NSRect screenRect;
NSArray *screenArray = [NSScreen screens];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
screenRect = [screen visibleFrame];


return [NSString stringWithFormat:@"%.1fx%.1f",screenRect.size.width, screenRect.size.height];










share|improve this question



















  • 2





    I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

    – Peter Hosey
    Feb 13 '11 at 6:44











  • Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

    – Vladimir Prudnikov
    Apr 3 '13 at 23:33











  • Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

    – adib
    Dec 9 '13 at 15:47












  • You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

    – WrightsCS
    Dec 9 '13 at 17:44













29












29








29


10






I am able to return the screen size using:



- (void) getScreenResolution 

NSArray *screenArray = [NSScreen screens];
NSScreen *mainScreen = [NSScreen mainScreen];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
NSRect screenRect = [screen visibleFrame];
NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main");

NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect));




Output:




Screen #0 (Main) Frame: 0, 4, 1344, 814




Is there a way to format 1344, 814 to 1344x814?




Edit:



This works perfectly:



- (NSString*) screenResolution 

NSRect screenRect;
NSArray *screenArray = [NSScreen screens];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
screenRect = [screen visibleFrame];


return [NSString stringWithFormat:@"%.1fx%.1f",screenRect.size.width, screenRect.size.height];










share|improve this question
















I am able to return the screen size using:



- (void) getScreenResolution 

NSArray *screenArray = [NSScreen screens];
NSScreen *mainScreen = [NSScreen mainScreen];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
NSRect screenRect = [screen visibleFrame];
NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main");

NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect));




Output:




Screen #0 (Main) Frame: 0, 4, 1344, 814




Is there a way to format 1344, 814 to 1344x814?




Edit:



This works perfectly:



- (NSString*) screenResolution 

NSRect screenRect;
NSArray *screenArray = [NSScreen screens];
unsigned screenCount = [screenArray count];
unsigned index = 0;

for (index; index < screenCount; index++)

NSScreen *screen = [screenArray objectAtIndex: index];
screenRect = [screen visibleFrame];


return [NSString stringWithFormat:@"%.1fx%.1f",screenRect.size.width, screenRect.size.height];







cocoa macos screen resolution






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 '11 at 6:03







WrightsCS

















asked Feb 13 '11 at 5:40









WrightsCSWrightsCS

46k21126173




46k21126173







  • 2





    I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

    – Peter Hosey
    Feb 13 '11 at 6:44











  • Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

    – Vladimir Prudnikov
    Apr 3 '13 at 23:33











  • Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

    – adib
    Dec 9 '13 at 15:47












  • You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

    – WrightsCS
    Dec 9 '13 at 17:44












  • 2





    I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

    – Peter Hosey
    Feb 13 '11 at 6:44











  • Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

    – Vladimir Prudnikov
    Apr 3 '13 at 23:33











  • Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

    – adib
    Dec 9 '13 at 15:47












  • You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

    – WrightsCS
    Dec 9 '13 at 17:44







2




2





I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

– Peter Hosey
Feb 13 '11 at 6:44





I suggest using fast enumeration instead of indexes for the loop. It will make it both faster and easier to read. Also, visibleFrame is not the same thing as frame; visibleFrame excludes the region occupied by the Dock or (when the Dock is hidden) the show-Dock trigger region, plus the menu bar.

– Peter Hosey
Feb 13 '11 at 6:44













Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

– Vladimir Prudnikov
Apr 3 '13 at 23:33





Your code may be much more simple. First of all for (NSScreen *screen in [NSScreen screens]).

– Vladimir Prudnikov
Apr 3 '13 at 23:33













Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

– adib
Dec 9 '13 at 15:47






Is there a way to get the screen size in real-life measurements? That is, in centimeters or inches?

– adib
Dec 9 '13 at 15:47














You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

– WrightsCS
Dec 9 '13 at 17:44





You will need to covert pixels to whatever you want. Should be easy enough. Just use the method above to get pixels, then covert.

– WrightsCS
Dec 9 '13 at 17:44












6 Answers
6






active

oldest

votes


















12














NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);






share|improve this answer


















  • 2





    Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

    – WrightsCS
    Feb 13 '11 at 6:00


















17














Finding the screen size in Mac OS is very simple:



NSRect e = [[NSScreen mainScreen] frame];
H = (int)e.size.height;
W = (int)e.size.width;





share|improve this answer

























  • Why are you casting the width and height to ints?

    – Peter Hosey
    Jul 20 '13 at 19:55






  • 1





    @PeterHosey Probably to indicate the height and width are ints :)

    – tomsmeding
    Aug 4 '13 at 9:13












  • @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

    – Peter Hosey
    Aug 4 '13 at 13:55


















14














In Swift 4.0 you can get the screen size of the main screen:



if let screen = NSScreen.main 
let rect = screen.frame
let height = rect.size.height
let width = rect.size.width



If you look for the size of the screen with a particular existing window you can get it with:



var window: NSWindow = ... //The Window laying on the desired screen
var screen = window.screen!
var rect = screen.frame
var height = rect.size.height
var width = rect.size.width





share|improve this answer
































    7














    For those guy who are looking for a way to get screen resolution:



    If you are programming a window based app, you can simply get the resolution from _window.screen.frame.size






    share|improve this answer






























      3














      edit/update



      Swift 4



      NSScreen.main?.frame // x 0 y 0 w 1,920 h 1,200
      NSScreen.main?.frame.width // 1,920.0
      NSScreen.main?.frame.height // 1,200.0



      Swift 3.x



      NSScreen.main()?.frame // x 0 y 0 w 1,920 h 1,200
      NSScreen.main()?.frame.width // 1,920.0
      NSScreen.main()?.frame.height // 1,200.0



      Swift 2.x



      NSScreen.mainScreen()?.frame // x 0 y 0 w 1,920 h 1,200
      NSScreen.mainScreen()?.frame.width // 1,920.0
      NSScreen.mainScreen()?.frame.height // 1,200.0





      share|improve this answer
































        0














        Swift 3 solution:



        NSScreen.main()!.frame






        share|improve this answer






















          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4982656%2fprogrammatically-get-screen-size-in-mac-os-x%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          12














          NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);






          share|improve this answer


















          • 2





            Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

            – WrightsCS
            Feb 13 '11 at 6:00















          12














          NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);






          share|improve this answer


















          • 2





            Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

            – WrightsCS
            Feb 13 '11 at 6:00













          12












          12








          12







          NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);






          share|improve this answer













          NSLog(@"%fx%f",screenRect.size.width, screenRect.size.height);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 13 '11 at 5:49









          GWWGWW

          33.3k69098




          33.3k69098







          • 2





            Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

            – WrightsCS
            Feb 13 '11 at 6:00












          • 2





            Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

            – WrightsCS
            Feb 13 '11 at 6:00







          2




          2





          Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

          – WrightsCS
          Feb 13 '11 at 6:00





          Sweet, return [NSString stringWithFormat:@"%.0fx%.0f",screenRect.size.width, screenRect.size.height]; worked perfectly to return 1024x768, thanks.

          – WrightsCS
          Feb 13 '11 at 6:00













          17














          Finding the screen size in Mac OS is very simple:



          NSRect e = [[NSScreen mainScreen] frame];
          H = (int)e.size.height;
          W = (int)e.size.width;





          share|improve this answer

























          • Why are you casting the width and height to ints?

            – Peter Hosey
            Jul 20 '13 at 19:55






          • 1





            @PeterHosey Probably to indicate the height and width are ints :)

            – tomsmeding
            Aug 4 '13 at 9:13












          • @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

            – Peter Hosey
            Aug 4 '13 at 13:55















          17














          Finding the screen size in Mac OS is very simple:



          NSRect e = [[NSScreen mainScreen] frame];
          H = (int)e.size.height;
          W = (int)e.size.width;





          share|improve this answer

























          • Why are you casting the width and height to ints?

            – Peter Hosey
            Jul 20 '13 at 19:55






          • 1





            @PeterHosey Probably to indicate the height and width are ints :)

            – tomsmeding
            Aug 4 '13 at 9:13












          • @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

            – Peter Hosey
            Aug 4 '13 at 13:55













          17












          17








          17







          Finding the screen size in Mac OS is very simple:



          NSRect e = [[NSScreen mainScreen] frame];
          H = (int)e.size.height;
          W = (int)e.size.width;





          share|improve this answer















          Finding the screen size in Mac OS is very simple:



          NSRect e = [[NSScreen mainScreen] frame];
          H = (int)e.size.height;
          W = (int)e.size.width;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 19 '13 at 12:09









          michaelb958

          3,81972433




          3,81972433










          answered May 19 '13 at 11:48









          mamadymamady

          18314




          18314












          • Why are you casting the width and height to ints?

            – Peter Hosey
            Jul 20 '13 at 19:55






          • 1





            @PeterHosey Probably to indicate the height and width are ints :)

            – tomsmeding
            Aug 4 '13 at 9:13












          • @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

            – Peter Hosey
            Aug 4 '13 at 13:55

















          • Why are you casting the width and height to ints?

            – Peter Hosey
            Jul 20 '13 at 19:55






          • 1





            @PeterHosey Probably to indicate the height and width are ints :)

            – tomsmeding
            Aug 4 '13 at 9:13












          • @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

            – Peter Hosey
            Aug 4 '13 at 13:55
















          Why are you casting the width and height to ints?

          – Peter Hosey
          Jul 20 '13 at 19:55





          Why are you casting the width and height to ints?

          – Peter Hosey
          Jul 20 '13 at 19:55




          1




          1





          @PeterHosey Probably to indicate the height and width are ints :)

          – tomsmeding
          Aug 4 '13 at 9:13






          @PeterHosey Probably to indicate the height and width are ints :)

          – tomsmeding
          Aug 4 '13 at 9:13














          @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

          – Peter Hosey
          Aug 4 '13 at 13:55





          @tomsmeding: Members of NSRect, NSPoint, and NSSize are CGPoints.

          – Peter Hosey
          Aug 4 '13 at 13:55











          14














          In Swift 4.0 you can get the screen size of the main screen:



          if let screen = NSScreen.main 
          let rect = screen.frame
          let height = rect.size.height
          let width = rect.size.width



          If you look for the size of the screen with a particular existing window you can get it with:



          var window: NSWindow = ... //The Window laying on the desired screen
          var screen = window.screen!
          var rect = screen.frame
          var height = rect.size.height
          var width = rect.size.width





          share|improve this answer





























            14














            In Swift 4.0 you can get the screen size of the main screen:



            if let screen = NSScreen.main 
            let rect = screen.frame
            let height = rect.size.height
            let width = rect.size.width



            If you look for the size of the screen with a particular existing window you can get it with:



            var window: NSWindow = ... //The Window laying on the desired screen
            var screen = window.screen!
            var rect = screen.frame
            var height = rect.size.height
            var width = rect.size.width





            share|improve this answer



























              14












              14








              14







              In Swift 4.0 you can get the screen size of the main screen:



              if let screen = NSScreen.main 
              let rect = screen.frame
              let height = rect.size.height
              let width = rect.size.width



              If you look for the size of the screen with a particular existing window you can get it with:



              var window: NSWindow = ... //The Window laying on the desired screen
              var screen = window.screen!
              var rect = screen.frame
              var height = rect.size.height
              var width = rect.size.width





              share|improve this answer















              In Swift 4.0 you can get the screen size of the main screen:



              if let screen = NSScreen.main 
              let rect = screen.frame
              let height = rect.size.height
              let width = rect.size.width



              If you look for the size of the screen with a particular existing window you can get it with:



              var window: NSWindow = ... //The Window laying on the desired screen
              var screen = window.screen!
              var rect = screen.frame
              var height = rect.size.height
              var width = rect.size.width






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 22 '18 at 13:17









              Andreas

              4591719




              4591719










              answered Jan 9 '15 at 14:48









              j.s.comj.s.com

              9491018




              9491018





















                  7














                  For those guy who are looking for a way to get screen resolution:



                  If you are programming a window based app, you can simply get the resolution from _window.screen.frame.size






                  share|improve this answer



























                    7














                    For those guy who are looking for a way to get screen resolution:



                    If you are programming a window based app, you can simply get the resolution from _window.screen.frame.size






                    share|improve this answer

























                      7












                      7








                      7







                      For those guy who are looking for a way to get screen resolution:



                      If you are programming a window based app, you can simply get the resolution from _window.screen.frame.size






                      share|improve this answer













                      For those guy who are looking for a way to get screen resolution:



                      If you are programming a window based app, you can simply get the resolution from _window.screen.frame.size







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 11 '13 at 5:27









                      JashengmatoJashengmato

                      7113




                      7113





















                          3














                          edit/update



                          Swift 4



                          NSScreen.main?.frame // x 0 y 0 w 1,920 h 1,200
                          NSScreen.main?.frame.width // 1,920.0
                          NSScreen.main?.frame.height // 1,200.0



                          Swift 3.x



                          NSScreen.main()?.frame // x 0 y 0 w 1,920 h 1,200
                          NSScreen.main()?.frame.width // 1,920.0
                          NSScreen.main()?.frame.height // 1,200.0



                          Swift 2.x



                          NSScreen.mainScreen()?.frame // x 0 y 0 w 1,920 h 1,200
                          NSScreen.mainScreen()?.frame.width // 1,920.0
                          NSScreen.mainScreen()?.frame.height // 1,200.0





                          share|improve this answer





























                            3














                            edit/update



                            Swift 4



                            NSScreen.main?.frame // x 0 y 0 w 1,920 h 1,200
                            NSScreen.main?.frame.width // 1,920.0
                            NSScreen.main?.frame.height // 1,200.0



                            Swift 3.x



                            NSScreen.main()?.frame // x 0 y 0 w 1,920 h 1,200
                            NSScreen.main()?.frame.width // 1,920.0
                            NSScreen.main()?.frame.height // 1,200.0



                            Swift 2.x



                            NSScreen.mainScreen()?.frame // x 0 y 0 w 1,920 h 1,200
                            NSScreen.mainScreen()?.frame.width // 1,920.0
                            NSScreen.mainScreen()?.frame.height // 1,200.0





                            share|improve this answer



























                              3












                              3








                              3







                              edit/update



                              Swift 4



                              NSScreen.main?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.main?.frame.width // 1,920.0
                              NSScreen.main?.frame.height // 1,200.0



                              Swift 3.x



                              NSScreen.main()?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.main()?.frame.width // 1,920.0
                              NSScreen.main()?.frame.height // 1,200.0



                              Swift 2.x



                              NSScreen.mainScreen()?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.mainScreen()?.frame.width // 1,920.0
                              NSScreen.mainScreen()?.frame.height // 1,200.0





                              share|improve this answer















                              edit/update



                              Swift 4



                              NSScreen.main?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.main?.frame.width // 1,920.0
                              NSScreen.main?.frame.height // 1,200.0



                              Swift 3.x



                              NSScreen.main()?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.main()?.frame.width // 1,920.0
                              NSScreen.main()?.frame.height // 1,200.0



                              Swift 2.x



                              NSScreen.mainScreen()?.frame // x 0 y 0 w 1,920 h 1,200
                              NSScreen.mainScreen()?.frame.width // 1,920.0
                              NSScreen.mainScreen()?.frame.height // 1,200.0






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 14 '18 at 19:12

























                              answered Jan 9 '15 at 17:51









                              Leo DabusLeo Dabus

                              136k32282353




                              136k32282353





















                                  0














                                  Swift 3 solution:



                                  NSScreen.main()!.frame






                                  share|improve this answer



























                                    0














                                    Swift 3 solution:



                                    NSScreen.main()!.frame






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      Swift 3 solution:



                                      NSScreen.main()!.frame






                                      share|improve this answer













                                      Swift 3 solution:



                                      NSScreen.main()!.frame







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 30 '17 at 22:28









                                      Aron GatesAron Gates

                                      11




                                      11



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4982656%2fprogrammatically-get-screen-size-in-mac-os-x%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Darth Vader #20

                                          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                                          Ondo