Closing a drawer

on clicked theObject
	tell window "main"
		set currentState to state of drawer "drawer"
		set leading offset of drawer "drawer" to 20
		set trailing offset of drawer "drawer" to 20
		
		if (the name of theObject) = "advancedOptions" then
			if currentState is equal to drawer opened or ¬
				currentState is equal to drawer opening then
				tell drawer "drawer" to close drawer
			else if currentState is equal to drawer closed or ¬
				currentState is equal to drawer closing then
				tell drawer "drawer" to open drawer on bottom edge
			end if
			
		end if
	end tell
end clicked

Script works fine with opening and the conditional that tests for drawer being closed or closing works (I teted by displaying a dialog on true). But the command: tell drawer “drawer” to close drawer does nothing. the drawer remains open.

I also tried:

tell drawer “drawer” to clase

which is the verbatum command found in the apple documentation. No go.

Hi :slight_smile:
Try this :


	on clicked theObject
		tell window "main"
			tell drawer "drawer"
				set currentState to state of it
				set leading offset of it to 20
				set trailing offset of it to 20
				
				if (the name of theObject) is "advancedOptions" then
					if currentState is in {drawer opened, drawer opening} then
						close drawer
					else if currentState is in {drawer closed, drawer closing} then
						open drawer on bottom edge
					end if
				end if
				
			end tell
		end tell
	end clicked

:wink:

Same behavior, opens but doesn’t close >.<

I like the code itself though, lot cleaner appearance.

I made a new project, copied the code over, ran it…it worked.

Deleted the code in the old project, copied the code back, ran it…it worked.

Don’t ask me. /shrug

I have also sometimes a little strange behaviors, perhaps due to the memory. it is often enough to restart the applications so that all returns in the order. :slight_smile:

Hi Krunk,

I’ve been wanting to dig into this issue but could not do it earlier…poor Internet connection where I am.

Anyway, I am surprised at the problem you’ve encountered working with drawers. Here’s a few lines of code that I use in my application to activate my “Help Drawer” on the right edge of the main window by clicking a button in the window “main”. It is probably not much different from yours. The properties (leading offset, trailing offset, etc) of my Help Drawer are defined elsewhere on awake from nib.

These few, simple lines of codes have always worked for me. No trouble whatsoever.

if the name of theWindowButton is "Help Button" then
	if the state of drawer "Help Drawer" is drawer closed then
		tell drawer "Help Drawer" to open drawer on right edge
		set contents of text field "HelpText" to "Hide Help"
	else
		tell drawer "Help Drawer" to close drawer
		set contents of text field "HelpText" to "Help"
	end if
end if

If you keep running into some quirky code behaviour on successive program compiles, you might want to do a clean build every now and then. This practise seems to “rejuvenate” (or clean up?) the process according to some posters in this forum.

Good luck.

archseed :slight_smile: