prompting....

on clicked theObject
set the_file to (((path to "dlib" from user domain as string) as text) & ".webim.ini") as file specification

set record_1 to text returned of (display dialog "What is the web adress?" default answer "http://openwebim.org/webim")
write_to_file(the_file, record_1)
set read_data to read the_file as text

on write_to_file(the_file, the_data)
	try
		set file_ref to (open for access the_file with write permission)
		set eof file_ref to 0
		write (the_data) to file_ref -- Write the_data as presented.
		close access file_ref
	on error
		try
			close access the_file
		end try
	end try
end write_to_file
end clicked

How do i get this to work? Basically it asks what url to use. then writes down in a file.

Hi,

to many useless coercions and the write_to_file handler must be outside the on clicked handler
The common syntax for the open and close commands is

open for access file the_file

with a path string in the_file
or

open for access the_file

with an alias in the_file


on clicked theObject
    set the_file to alias ((path to library folder from user domain as text) & ".webim.ini")
    set record_1 to text returned of (display dialog "What is the web adress?" default answer "http://openwebim.org/webim")
    write_to_file(the_file, record_1)
    set read_data to read the_file as text
end clicked

on write_to_file(the_file, the_data)
    try
        set file_ref to (open for access the_file with write permission)
        set eof file_ref to 0
        write the_data to file_ref -- Write the_data as presented.
        close access file_ref
    on error
        try
            close access the_file
        end try
    end try
end write_to_file

Nope… that code won’t do. IT saves fine, but it says, can’t find .webim.ini file.

OK. then this way

on clicked theObject
	set the_file to ((path to library folder from user domain as text) & ".webim.ini")
	set record_1 to text returned of (display dialog "What is the web adress?" default answer "http://openwebim.org/webim")
	write_to_file(the_file, record_1)
	set read_data to read file the_file as text
end clicked

on write_to_file(the_file, the_data)
	try
		set file_ref to (open for access file the_file with write permission)
		set eof file_ref to 0
		write the_data to file_ref -- Write the_data as presented.
		close access file_ref
	on error
		try
			close access file the_file
		end try
	end try
end write_to_file

:smiley: thanks, sorry 4got 2 post that i got it 2 work.

on clicked theObject
	set the_file to (((path to "dlib" from user domain as string) as text) & ".webim.ini") as file specification
	set record_1 to text returned of (display dialog "What is your web address to your WebIM?" default answer "http://openwebim.org/webim")
	write_to_file(the_file, record_1)
	set read_data to read the_file as text
end clicked


on write_to_file(the_file, the_data)
	try
		open for access the_file with write permission
		set eof of the_file to 0
		write the_data to the_file starting at eof
		close access the_file
	on error
		try
			close access the_file
		end try
	end try
end write_to_file

this line contains two useless coercions as text - as file specification (btw: file specification is outdated)
“dlib” is correct but library folder makes the script more readable

This is better code


.
set the_file to ((path to library folder from user domain as text) & ".webim.ini")
.