Full Screen Windows - Really Cool

After success working out the titleless windows (thanks to you all) I thought it would be neet to have a full screen window. After checking around the net I came across some code written by “kitzkikz” http://www.macosxhints.com/article.php?story=20030804193518188 and after some very slight modifications I was able to get it to work.

To recap:
1)Start with a basic applescript studio project and add the two Objective-C files Fullscreen.h and Fullscreen.m

Fullscreen.h

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
@interface NSApplication (ASKAFullScreen)

  • (NSWindow *)beginFullScreen;
  • (void)endFullScreen;
    @end

Fullscreen.m

#import “Fullscreen.h”
NSWindow *fsWindow;
@implementation NSApplication (ASKAFullScreen)

  • (NSWindow *)beginFullScreen
    { fsWindow = [
    [NSWindow alloc]
    initWithContentRect:[[NSScreen mainScreen] frame]
    styleMask:NSBorderlessWindowMask
    backing:NSBackingStoreBuffered
    defer:NO];
    NSView *fsView=[[NSView alloc] initWithFrame:[fsWindow frame]];
    [fsWindow setContentView:fsView];
    NSImageView *fsImage = [[NSImageView alloc] initWithFrame:[fsView frame]];
    [fsView addSubview:fsImage];
    [fsWindow setBackgroundColor:[NSColor redColor]];
    [NSMenu setMenuBarVisible:0];
    [fsWindow makeKeyAndOrderFront];
    return fsWindow;
    }
  • (void)endFullScreen
    { [NSMenu setMenuBarVisible:1];
    [fsWindow close];
    }
    @end
  1. Then add a button to a window and in your main script add:

on clicked theObject
set theWindow to (call method “beginFullScreen”)
delay 5
call method “endFullScreen”
end clicked

Note: I made the window color red instead of the original black. I couldnt get a hold of "kitzkikz" to thank him but I imagine that for all you Object-C programmers this isnt really anything special.


Anyway, my question is (you were probably wondering whether I even had one):

How do you get a window that youve already made (ex: a window that includes a photo) to go full screen? In this example weve made a new window programatically, but what if you already have a window? Is it possible to reference it somehow?

Any help/ideas would be Greatly appreciated.

Thank you all for your time and I look forward to hearing from you soon.

Bruce
Follow Your Dreams

There have been a couple threads covering this topic. This one and this one discuss some possible ways of doing this. Basically YES, you can make an existing window go full screen, but you need to know what the screen resolution is in order to do that. Because screen resolutions change, you can’t hardcode a resolution as it will not always be correct for every user. This is assuming it’s a distribution app. If you’re writing it for yourself, you could hardcode it. There is no pure applescript method of getting the screen res, so you’ll have to try one of the obj-c methods provided by mooresan in the second thread above. Once you get the resolution, you can easily use applescript to set the size of the window using the bounds property…

tell window "theWindow"
  set bounds to {0,0,1024,768}
end tell

j

I haven’t tested this extensively but it appears to get the correct screen resolution for me. FYI, the handler was snagged from one of Apple’s scripts that resizes a Safari window to full screen. :slight_smile:

set resolution to desktop_size()

on desktop_size()
	tell application "System Events"
		tell process "Finder"
			repeat with i from 1 to the count of windows
				if the position of window i is {0, 0} then
					return the size of window i
				end if
			end repeat
		end tell
	end tell
end desktop_size

– Rob

You’re right, this does work. I stand corrected. I don’t like that it requires ‘enabled for assistive devices’ turned on, though. Having more interest in developing apps than scripts, I think there are a handful of reasons why other ways might be better. If it’s being used in a personal, predictable environment it would be OK. But in this case, you could just hardcode the dimensions. :slight_smile:

j

Since you’re in AS Studio, it’s even easier with a method call to the NSScreen class:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks for the info. (I`ve been away for a few days and am late getting back into the discussion, sorry.)

Jon, you mentioned:


–full frame:
set {x1, y1, x2, y2} to call method “frame” of mainScreen

–frame without menubar and Dock:
set {x1, y1, x2, y2} to call method “visibleFrame” of mainScreen

I have no problem with the “full frame” version (By the way, thank you very much) but I can`t get the “frame without menubar and Dock” version to work. It just gives me a full frame window like the “full frame” version. Any ideas?

Something else I noticed is that if you take out the:
[fsWindow makeKeyAndOrderFront];
from the Fullscreen.m file then you get the desktop showing with no TitleBar. Is that cool or is that stange?