Myriad Helpers: a "Choose folder" as sheet?


My app deals with folder contents and not with individual files.

The Myriad Helpers (coming along with Shane Stanley’s AppleScriptObjC Explored book) work very well with “Alerts” and “Open file” dialogs as window sheets. Is it possible to use them with “Choose folder” dialogs?

Thank you!

I think a “choose folder” dialog is just an open panel with setCanChooseFiles set to no and setCanChooseDirectories set to yes. If you look at the first method in Myriad Helpers, OpenSavePanelTest.applescript, you will see this:

on showOpenPanel_(sender)
		tell current application's NSOpenPanel to set thePanel to makeOpenAt_types_files_multiples_prompt_title_(path to documents folder, {"txt", "pdf"}, true, false, "Choose a Folder", "Folder Chooser")
		tell thePanel to showOver_calling_(mainWindow, {"openSheetDone:", me})
	end showOpenPanel_

If you just change that true to false, it will allow you to choose folders but not files (I already changed the prompt and title settings, so I don’t remember what Shane had in there originally). The only “problem” is that the button still says open rather than choose which would be nice – I don’t see any way to change that without subclassing NSOpenPanel


You use the rather-poorly named setPrompt: method.

Actually, you don’t need to subclass NSOpenPanel to change the button title – The prompt is the title of the right button. I made a choose panel with the following code (this doesn’t require any Myriad Helpers files):

script ChooseDialogAppDelegate
	property parent : class "NSObject"
	on applicationWillFinishLaunching_(aNotification)
		set op to current application's NSOpenPanel's openPanel()
		op's setCanChooseFiles_(0)
		op's setCanChooseDirectories_(1)
		op's setTitle_("Choose a Folder")
		op's setPrompt_("Choose")
		op's setMessage_("Put something here if you want to")
		op's runModal()
		log op's URLs()
	end applicationWillFinishLaunching_
end script


Yes, I agree, that is poorly named. I was looking for a way to do this when I found the NSWindow method, defaultButtonCell, which let me change the button with op’s defaultButtonCell()'s setTitle_(“Choose”), but then noticed that setting the prompt afterwards changed the title of the button to the prompt. :rolleyes:



I think the reason I didn’t realize what the prompt was, is that you changed its meaning in your Myriad Helpers. I had used the openPanel methods in one of my programs and the string provided to the prompt parameter in your makeOpenAt:types:files:multiples:prompt:title: method shows up where the message should show up, not in the button title. Is this what you intended?


Everything is working fine – thank you everybody!


Yes, I hummed and harred about that. In the end, I decided to try to match wording AS users would be familiar with (choose file with prompt…). I figured changing the button label would be a rarer event. But I knew it was a bit of a no-win choice…