LiveCode LessonsHow To - Step-By-Step Guides To Tasks In LiveCode Using dialogsHow to control where the answer file/folder dialog starts

How to control where the answer file/folder dialog starts

This is a very simple lessons that explains how to make the 'answer file' and 'answer folder' dialogs start at a specific location of your computer.

The basic answer file command

The basic answer file command

Start by creating a new stack and:

1) Drag on a new button

2) Bring up the script editor for the button

3) Put in the following script

on mouseUp

answer file "Select a file"

end mouseUp

The result

The result

Click on the button and see where the dialog has taken you. In my case, the last time I loaded the the file dialog it was in the 'CONFERENCE' folder within my 'Work' folder. If you now navigate anywhere on your drive, close the dialog, and press the button again you will notice that it loads in the same folder as when you closed the dialog last.

Make the file chooser always start in a specific location

We need to use the 'with' syntax which is detailed in the Documentation. By specifying '/users/ben/Desktop' I am telling the dialog to open at that folder. The user can still choose to go anywhere but each time the user clicks my button they will be presented with my 'Desktop' folder as their start point.

on mouseUp

answer file "Select a file" with "/users/ben/Desktop"

end mouseUp

You can or course set this in script allowing you to dynamically alter the place a user starts from.

on mouseUp

local tStartDirectory

put "/users/ben/Desktop" into tStartDirectory

answer file "Select a file" with tStartDirectory

end mouseUp

2 Comments

Tim

Very nice, it worked perfectly for opening up a folder in a specific directory, thank you for posting this.

Warren

It should be mentioned that some directories appear to require the use of the trailing slash in order to work, at least in OS X 10.5. For example:

answer "select a file" with "/Applications/"

or: ........ with "/Volumes/mydisk/"

I haven't found any directories which fail using the trailing slash. It also seems that setting a folder within any of these "troublesome" locations works without using it.

It may be worth adopting the convention of always using the trailing slash in order to avoid some head scratching.

Add your comment

E-Mail me when someone replies to this comment