Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How do I make an AppleScript that displays a drop-down menu without using Xcode?

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

There is no built in concept of a menu in the dialogs-alerts within the AppleScript language.

The closest you could do would be to name some dummy files (in a temporary folder) with the appropriate action and have the user choose the file labeled with the action you wanted to perform.

open folder blah
  with selected file bah
    do whatever

A horrendous "solution" to a problem that needs a cocoa menu - whether you make it in Xcode or someone else does - Xcode/IB is the tool that creates a menu. MacRuby is a nice way to script an app that needs a more full featured UI than AppleScript. You don't need Xcode/IB to ruby up an app from pure script.

You could create a NIB using Interface Builder and script it all using AppleScript, but the nib defines the menu itself - not AppleScript (even if AppleScript can populate or delete the menu items at run time).

share|improve this answer
    
Thank you very much!! –  daviesgeek Aug 12 '11 at 20:27
add comment

One option would be to use CocoaDialog:

set l to {"aa", "bb", "cc"}
set choices to ""
repeat with x in l
    set choices to choices & quoted form of x & " "
end repeat
set dialog to paragraphs of (do shell script "/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" & " standard-dropdown --title title --text text --items " & choices)
if item 1 of dialog is "2" then return -- pressed cancel button
item ((item 2 of dialog) + 1) of l

You could also just use choose from list:

choose from list {"aa", "bb", "cc"} with title "title" with prompt "prompt" default items "bb" with multiple selections allowed

share|improve this answer
add comment

Additionally, if you just need a list to choose from, you could also do

choose from list listYouDefined with prompt "Choose from the list."

Google "AppleScript Choose from list".

share|improve this answer
add comment

You don't need Xcode for AppleScript. Just open the 'AppleScript Editor' in 'Applications/Utilities' (Finder shortcut for the Utilities folder: ⌘+shift+u). There is some sample code for dropdown menus here.

share|improve this answer
    
I have already looked at that link. The script requires a NIB/Xcode interface. –  daviesgeek Aug 12 '11 at 20:26
    
It's a great example of how AppleScript can modify the menu items at run time though :-) –  bmike Aug 12 '11 at 20:33
    
Yeah, but not exactly what I'm looking for. –  daviesgeek Aug 12 '11 at 21:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.