use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
-- create a view
set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 400, 40))
-- create a button
set theButton to current application's NSButton's alloc()'s initWithFrame:(current application's NSMakeRect(100, 10, 150, 20))
-- make button a checkbox and give it a title
theButton's setButtonType:(current application's NSSwitchButton)
theButton's setTitle:"I am a checkbox"
-- add the checkbox to the view
theView's addSubview:theButton
-- make open panel
set openPanel to current application's NSOpenPanel's openPanel()
tell openPanel
-- set main values
its setMessage:"Your message here" -- AS's prompt
-- other values you *can* set
its setAllowsMultipleSelection:true -- AS's multiple selections allowed
its setAllowedFileTypes:{"txt"} -- AS's of type. Provide missing value for all types
-- add the view to the panel
its setAccessoryView:theView
end tell
-- show panel
set returnCode to openPanel's runModal()
if returnCode is (current application's NSFileHandlingPanelCancelButton) then
error number -128
end if
-- get chosen paths and tags
set thePosixPaths to (openPanel's |URL|()'s valueForKey:"path") as list
set theTags to openPanel's tagNames()
if theTags = missing value then
set theTags to {}
else
set theTags to theTags as list
end if
set theState to theButton's state() as boolean
return {thePosixPaths, theTags, theState}
You can get more complex -- for example, a control in the accessory view can call a handler in your script while the dialog is still showing. Add these two lines after setting theButton's title:
That tells the checkbox that when it's clicked it should call a handler named "on checkboxChecked:" that belongs to me (the script). Now add a handler of that name at the end:
Clicking the checkbox should now display a dialog.
Just remember to run it in the foreground.