Allowed coercions
- List with one item
- string
Syntax
set fSpec to (new file default name "urlfile")
Description
The
file specification class can reserve the name and
path for a file, even if the file has not yet been saved to the hard
disk. The URL Access
Scripting
scripting addition takes a value of type
file specification for both its
download and upload
commands.
Examples
This
code requests the user to name a file and choose its saving location
(with the new file scripting-addition command)
then downloads a web page to the file:
set fspec to (new file default name "urlfile")
tell application "URL Access Scripting" to download "http://www.¬
parkerriver.com" to fspec
new file displays a dialog box that allows the
user to name and choose the location for a file, but it
doesn't actually save the file. It returns the file
information as a file specification data type.
The following code gets a file specification, and
then sends a save Apple event to the text editor
BBEdit. The text editor then saves its front window to the
file specification the applet user had previously
created:
set newFileSpec to¬
(new file with prompt "where would you like the future file saved?")
(* returns a file specification object *)
tell application "BBEdit 5.1"
save window 1 to newFileSpec
end tell
The info for
scripting addition takes a file
specification parameter. It gives you a
substantial amount of information about a file
that's been saved to disk, including the name, size
in bytes, file type, and creator type. However, the info
for command will return an error if the
file specification data has not
yet been saved:
set filespec to¬
(new file with prompt "Where do you want a new file saved?")
tell application "BBEdit 5.1"
save window 1 to filespec
end tell
set fileInfo to (info for filespec)
display dialog "name: " & (name of fileInfo) & return & "size: " &¬
(size of fileInfo)
|