revUp - Updates and news for the LiveCode community
Issue 147 | January 25th 2013 Contact the Editor | How to Contribute

Answer file filtered for Applications
This lesson will show you how to filter the files shown in an answer file dialog so that it only shows applications

By Stuart Gundry

In article 1 this week we saw a very simple example of using the answer dialog to put "Hello" on screen. This is a more sophisticated use, where you can select and display only application files.

Show the answer file dialog

Click the image to zoom

First we write a simple script to show the answer file dialog and handle the file path returned.

on mouseUp
    ## Shows a select file dialog filtered to only show applications then puts the selected filepath into field "Filename"
    answer file "Select File:"
    put it into field "Filename"
end mouseUp

Filter the answer file dialog

Click the image to zoom

The answer file script can be filtered by file type using the format "tag|extensions|filetypes". In this case, for Windows computers we use "Applications|exe|*". We can put any number of comma delimited options in the extensions and filetypes sections. Files that match any of those extensions will be shown. We could also add another line of "tag|extensions|filetypes" if we wanted the user to select from several filters using the "Files of type" option menu.

on mouseUp
     ## Shows a select file dialog filtered to only show applications then puts the selected filepath into field "Filename"
     ## Windows applications have the extension *.exe
    answer file "Select Application:" with type "Applications|exe|*"
    put it into field "Filename"
end mouseUp

Filter by file type depending on operating system

click the image to zoom

Different operating systems use different application file types, the operating system can retrieved using the platform function.

on mouseUp
    ## Shows a select file dialog and filters to only show applications for the current operating system
    ## Different OSes use different extensions for application files
    if the platform is "Win32" then
        ## Windows applications have the extension *.exe
        answer file "Select Application:" with type "Applications|exe|*"
    else if the platform is "MacOS" then
        ## Mac OS and OS X use APPL
        answer file "Select Application:" with type "Applications|app|APPL"
    else
        ## Unix based OSes don't have a particular application type
        answer file "Select Application:"
    end if
    put it into field "Filename"
end mouseUp

 

Main Menu

What's New


Get On-Rev Hosting, with $499 cashback