Re: Choose File
Re: Choose File
- Subject: Re: Choose File
- From: "Gary (Lists)" <email@hidden>
- Date: Thu, 19 Oct 2006 13:43:20 -0400
"Ruby Madraswala" wrote:
> How can I set a default folder, so the choose command will always open the
> default folder to select files from?
>
> set FileToOpen to choose file with prompt "Select file"
Hi Ruby.
As I've noted your continued progress and successes with AppleScript,
perhaps it is a good time to reintroduce the idea of "dictionaries".
(Revisiting topics as I progress is one way in which I learn, so perhaps
this refresher will be of help to you as well.)
Each application (which is scriptable) as well as any osax [1] you have
installed each have a dictionary. (AppleScript itself does, too.) [2]
So, the command "choose file" comes from some dictionary. This happens to
be from a pre-installed, and basically required, osax called
"StandardAdditions.osax". [3] These commands are, as the name implies,
Standard even though they are bundled into an osax and not the actual AS
engine itself.
Reading from that dictionary, we find the command of interest ("choose
file"), and that says:
<StandardAdditions.osax>
choose file -- Choose a file on a disk or server
* [with prompt string] -- a prompt to be displayed in the file chooser
* [of type list of string] -- restrict the files shown to only these
file types
* [default location alias] -- the default file location
* [invisibles boolean] -- Show invisible files and folders? (default is
true)
* [multiple selections allowed boolean] -- Allow multiple items to be
selected? (default is false)
* Result: alias -- to the chosen file
</StandardAdditions.osax>
So, we see that there is an optional (denoted by the surround [ and ])
command parameter called 'default location', which takes an 'alias' as its
argument.
Taking your original command:
> set FileToOpen to choose file with prompt "Select file"
we would then add that optional information, to get:
-- Just as an example.
set StartFolderForSelection to alias "HD:users:someuser:"
-- This is a single line only.
set FileToOpen to choose file with prompt "Select file" default location
StartFolderForSelection
I hope that helps, Ruby.
--
Gary
[1] 'osax' means "OSA eXtension". AppleScript is in a (small) group of OSA
languages. OSA means "open scripting architecture". So, AppleScript is one
OSA language, and an 'osax' is an extension of that language. Yummy! More
acronym soup.
The dictionary of an installed osax can be examined through the 'Open
Dictionary' command of your script editor.
For all AppleScript authors, I recommend the "HTMLDictionary" application,
which allows one to drop any application or osax and generate a text and/or
HTML text version of the dictionary. Then, one can keep them in a single
folder and open them very quickly in a web browser. The HTML version
produced is fully linked between terms, so you can hop around as dictated by
the logic of your reading.
<http://appscript.sourceforge.net/download.html>
(I don't know why this tool is included in the downloads section of the
'appscript' Sourceforge space, but that's where it is.)
[2] I use the Smile script editor, which allows one to open the AppleScript
dictionary directly. I do not know how users of other editors open this
dictionary.
[3] How one discovers _which_ dictionary a particular command comes from is
often a real mystery. As I said, I use the Smile editor, which provides a
nice feature where one can select a command and then find the command in the
installed osax or other Smile-accessible components. It's quite handy to be
able to select the text "choose file" in a script and then locate the
command in a particular dictionary. It's one of the best features of Smile
(and there are exactly 3,497 best features of Smile, by the way.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Choose File (From: "Ruby Madraswala" <email@hidden>) |