simple interactive script

Discussion in 'Mac Programming' started by md5, Sep 9, 2009.

  1. md5 macrumors newbie

    Jun 13, 2009
    I have a bash script,

    how do I make selections? For example I start the script and if there is directory called "test" on the desktop how do I give a choice "Do you want to delete it? y/n"

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Use the osascript command to execute AppleScript that presents a dialog and returns the result on its stdout or stderr. Read 'man osascript', then refer to any AppleScript tutorial on how to present simple dialogs.

    Since AppleScript is typically framed as a "tell app "SomeAppHere" ..." series of statements, you can tell the app System Events to do things if you don't have any other app at hand. You can also browse and experiment with AppleScripts using Script Editor (Spotlight search for it). To get the scripting terms, command-shift-O will present a list of scriptable apps; choose System Events and dig in.

    There are also other command-line runnable languages that can present a dialog. The ones that come to mind are more complex than osascript for a simple dialog, though.

Share This Page