Hey guys, is it possible to make it so theres nothing behind a window but a black colour.
Im trying to make it so when my alarm is set off the only thing a theft can see if a black and white flashing backround and a login box, I have looked around but cant find a way to do such a thing.
Edit: Sorry - my mistake - I thought we were in the AppleScript Studio/xCode forum - this of course will only work in AppleScript Studio, sorry …
Hi semaja2,
don’t think this is possible with pure AppleScript. Here’s how to whith a little help from Objective-C:
add a new file of type ‘Objective C’ class to your project, called ‘blackback’ (for example)
edit the two new files ‘blackback.h’ and ‘blackback.m’ so that they look like so:
blackback.h:
#import <Cocoa/Cocoa.h>
@interface blackback : NSObject {}
+(NSWindow *)makeBlackBackgroundWindow;
@end
blackback.m:
#import "blackback.h"
@implementation blackback
+(NSWindow *)makeBlackBackgroundWindow{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *fullscreen = [[NSWindow alloc]
initWithContentRect:[[NSScreen mainScreen] frame]
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[fullscreen setBackgroundColor:[NSColor blackColor]];
[fullscreen retain];
[pool release];
return fullscreen;
}
@end
then you cann call it from your applescript like so:
set blackBack to call method "makeBlackBackgroundWindow" of class "blackback"
call method "makeKeyAndOrderFront:" of blackBack with parameter null
call method "makeKeyAndOrderFront:" of window "main" with parameter null
-- do whatever you want ...
-- and hide or close the black one if it is no longer needed:
set visible of blackBack to false
Hope that helps,
Dominik
Note: this won’t hide the menu - and won’t black a second monitor/screen - tell me if you need to solve this …
being able to hide the menu bar could be very useful, how much work would it be to do that?
hi semaja2,
here’s how to (AppleScript Studio only of course …)
hide:
call method "setMenuBarVisible:" of class "NSMenu" with parameter 0
show:
call method "setMenuBarVisible:" of class "NSMenu" with parameter 1
Is there anyway to make sure the password dialog doesnt get hidden by the blackback, like if i accidently click on the black backround the password screen disappears behind it unless i alt+tab back.
also is there any way i could put a image on the backround? maybe being able to make it look like it is still the desktop but not the actual desktop
Hi semaja,
easiest solution for this is probably to use a panel instead of a window (‘dispaly panel …’ instead of ‘call method “makeKeyAndOrderFront:” of window “main” with parameter null’ in the applescript above)
it is … here’s the code:
add in the blackback.h file:
+(NSWindow *)fullscreenWindowWithPictureFromPath:(NSString *)thePicPath;
and in the blackback.m file:
+(NSWindow *)fullscreenWindowWithPictureFromPath:(NSString *)thePicPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *picURL = [[NSURL alloc] initFileURLWithPath:thePicPath];
NSImage *theBackgroundPic = [[NSImage alloc] initWithContentsOfURL:picURL];
NSWindow *fullscreen = [[NSWindow alloc]
initWithContentRect:[[NSScreen mainScreen] frame]
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
NSSize winSize = [fullscreen frame].size;
NSImageView *img = [[NSImageView alloc] initWithFrame:NSMakeRect( 0.0, 0.0, winSize.width,winSize.height )];
[fullscreen setContentView:img];
[img setImageScaling:NSScaleToFit];
[img setImage:theBackgroundPic];
[fullscreen retain];
[pool release];
return fullscreen;
}
and replace in the applescript:
set blackBack to call method "fullscreenWindowWithPictureFromPath:" of class "blackback" with parameter thePOSIXpic
where thePOSIXpic is a POSIX style path to a picture. The Picture will be stretched to fill the screen if needed …
D.
What do you mean by display panel, what i have is a nib file which contains a window called main which has all the dialog in it
Since I don’t know your application I thought it might be possible to separate the login dialog from your main window and put it in a panel. I f this is not possible/wanted then things are a little bit more complicated.
Maybe you can tell me some more details about your application and this dialog - then I’ll try to help you. In cas you don’t want to discuss details about your project here feel free to pm or eMail me …
Dominik
I sent you a PM a while ago but dont know if you recieved so i sent you email just now, but for anyone else the source code it available on semaja2.net under the MultiAlarm tab