Re: Applescript to write answers to individual file names
Re: Applescript to write answers to individual file names
- Subject: Re: Applescript to write answers to individual file names
- From: Barry Wainwright <email@hidden>
- Date: Thu, 08 Dec 2005 13:41:23 +0000
- Thread-topic: Applescript to write answers to individual file names
Title: Re: Applescript to write answers to individual file names
On 7/12/05 21:01, "David Thompson" <email@hidden> wrote:
> Hello everyone,
>
> I am new to this board and am glad I have found it. I am trying (ha
> ha trying) to figure out how to write an applescript (or build it
> through automator) in which the script does the following:
>
> take the input from a popup window: enter your user name, and takes
> the answer and writes it into a file in /tmp/uname
> I also would like the popup window to ask for the users" password and
> take that answer and write it to a file in /tmp/passwd
> I need to have 2 separate files.
>
> The reason I need this is I need to have a user friendly interface in
> order to question users for their username and passwords and then
> take those 2 answers and write them into another file within the system.
>
> I know that in UNIX scripting its easy to write the file such as:
> username answer > /tmp/uname
>
> This doesn't appear to work the same in the applescript world.
> Any help that I might be able to get on this subject would be greatly
> appreciated as I am lost on the whole applescript world.
>
> I apologize if this topic has been covered in length before.
> Thanks,
>
> David
>
The 'Applescript' way to write anything to a file is to use the File Read/Write commands in StandardAdditions:
File Read/Write : Commands for reading and writing information in a file
open for access : Open a disk file for the read and write commands
open for access file -- the file or alias to open for access. If the file does not exist, a new file is created.
[write permission boolean] -- whether to allow writing to the file.
Result : small integer -- a file reference number; use for ‘read’, ‘write’, and ‘close access’
close access : Close a file that was opened for access
close access anything -- the file reference number, alias, or file reference of the file to close
read : Read data from a file that has been opened for access
read anything -- the file reference number, alias, or file reference of the file to read
[from double integer] -- starting from this position; if omitted, start at last position read from
[for double integer] -- the number of bytes to read from current position; if omitted, read until the end of the file…
[to double integer] -- …or stop at this position…
[before string] -- …or read up to but not including this character…
[until string] -- …or read up to and including this character
[using delimiter string] -- the value that separates items to read…
[using delimiters a list of string] -- …or a list of values that separate items to read
[as type class] -- the form in which to read and return data
Result : anything -- the data read from the file
write : Write data to a file that was opened for access with write permission
write anything -- the data to write to the file
to anything -- the file reference number, alias, or file reference of the file to write to
[starting at double integer] -- start writing at this position in the file
[for double integer] -- the number of bytes to write; if not specified, write all the data provided
[as type class] -- how to write the data: as text, data, list, etc.
get eof : Return the length, in bytes, of a file
get eof anything -- a file reference number, alias, or file reference of a file
Result : double integer -- the total number of bytes in the file
set eof : Set the length, in bytes, of a file
set eof anything -- a file reference number, alias, or file reference of a file
to double integer -- the new length of the file, in bytes. Any data beyond this position is lost.
Here's a snippet to show it in use:
set thePath to ((path to temporary items) as text) & "uname"
try
set ufile to open for access thePath with write permission
on error
-- was the file already open? try to close it
try -- just in case it wasn't open!
close access thePath
end try
end try
set uName to text returned of (display dialog "what is your UserName?" default answer "myName")
write uName to ufile
close access ufile
A similar thing could be done with the password, but I would recommend applying some obfustication routine before you write the password to a plain text file!
--
Barry
_______________________________________________
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