open panel in different area


Is it possible to have a panel open half way down a main window, instead of opening from the top of a main window?
if it is possible how would I go about making it happen please.?

Hi Budgie,

it is possible. But you need to ceate a transparent window at the place where you want to show your panel. I would use a NSWindow subclass and give it some methods to create and remove a ‘slave’ (child) window:

[code]// MasterAndSlaveWindow.h

#import <Cocoa/Cocoa.h>

@interface MasterAndSlaveWindow : NSWindow {
NSWindow *slaveWin;

-(void)addSlaveWithXOffset:(float)xOffset yOffset:(float)yOffset;
-(NSWindow *)slave;

[code]// MasterAndSlaveWindow.m

#import “MasterAndSlaveWindow.h”

@implementation MasterAndSlaveWindow

  • (id) init{
    self = [super init];
    if (self != nil) {
    slaveWin = nil;
    return self;

  • (void) dealloc{
    if (slaveWin != nil) [slaveWin release];
    [super dealloc];

-(void)addSlaveWithXOffset:(float)xOffset yOffset:(float)yOffset{

if(slaveWin != nil) [slaveWin release];

NSRect slaveFrame = [self frame];
slaveFrame.origin.x += xOffset;
slaveFrame.origin.y += yOffset;

slaveWin = [[NSWindow alloc] initWithContentRect:slaveFrame
			defer: NO];
[slaveWin setOpaque:NO];
[slaveWin setBackgroundColor:[NSColor clearColor]];
[self addChildWindow:slaveWin ordered:NSWindowAbove];
[slaveWin makeKeyAndOrderFront:nil];


-(NSWindow *)slave{
return slaveWin;

[self removeChildWindow];
[slaveWin orderOut:nil];
[slaveWin release];


  • add these two files to you project
  • drop the .h file on your nib in Interface builder and set the new Window class as custom class in Interface Builder (Apple+5 in IB < 3.0 or Apple+6 in IB 3.0)
  • then you can use it from AppleScript:
    call method "addSlaveWithXOffset:yOffset:" of (window "window") with parameters {20.0, -140.0} -- create an invisible 'slave' window with the given offset
    set can choose directories of open panel to true
    set can choose files of open panel to false
    display open panel attached to (call method "slave" of (window "window")) -- ask your window for it's slave and attach the panel to it

Hope that helps …


Hi Dominik

Cheers for code and instruction, very much appreciated.

First of all, I’m a newbie! I’ve used applescript for a decade, but am only just starting to use Xcode/ASOC. I have to thank the entire macscripter community for all their posts. I’ve learned a lot and made great progress on a project I’m working on. I want to particularly thank Shane for his book which I’ve just purchased, and have to thank Ric for his assistance implementing core data in my project.

This is exactly what I need(i think), but I can’t seem to make it build in Xcode 4.3.2. Getting error on the MasterAndSlaveWindow.m file with “missing end” and another error…I’ve copied/pasted correctly, but assume that updates to Xcode require some changes to the code? I’ve searched but not finding anything helpful (likely because I don’t know what I’m looking for)

Is there a “simple” update that can make this work in Lion/Xcode 4.3.2? :slight_smile: