Open Panel Question....

i am using the open panel to get the string of a folder.

this is my current script:


-- Choose Site Folder
on set_choose_folder()
	
	-- set the_site_folder to (choose folder) as string
	
	
	set can choose directories of open panel to true
	set can choose files of open panel to false
	display open panel attached to window "main"
	
end set_choose_folder


on panel ended theObject with result withResult
	
	-- what do i put?

end panel ended
-- End


what do i put in there to get the identical result as in simply this:



set the_site_folder to (choose folder) as string


thanks :smiley:

Hi Max,


-- Choose Site Folder
on set_choose_folder()
	-- set the_site_folder to (choose folder) as string
	set can choose directories of open panel to true
	set can choose files of open panel to false
	display open panel attached to window "main"
end set_choose_folder


on panel ended theObject with result withResult
	if withResult is 1 then
		set the_site_folder to (path name of open panel) as POSIX file as alias
	end if
end panel ended
-- End

Note: You can find the code in the Open Panel project in /Developer/Examples/AppleScript Studio/

stefan,

i tried your suggestions but it ain’t working. the result needs to be a string and it needs to be a folder.

i changed the alias to string. alias does not work at all - but the string makes it work yet wrongly. more on that later.

i use this folder set for this script:


on create_credits_file()
	
	set credits_contents to "<!-- Credits -->"
	
	set credits_file to credits_contents & (ASCII character 10)
	set credits_file to credits_file as string
	
	set new_file_path to the_site_folder & "credits.txt"
	set file_ref to (open for access file new_file_path with write permission)
	set eof file_ref to 0
	write credits_file to file_ref as «class utf8»
	close access file_ref
	
end create_credits_file

originally with the simply (choose folder) action, it has set the the_site_folder as a string and has placed the file into that folder with the name credits.txt.

now on the other hand, it creates the file in the same location as the folder is. it also names the file incorrectly. it gives it the name of the selected folder + credits.txt … wrong :smiley:

it needs to return the same result as if i would use this script:


set the_site_folder to (choose folder) as string

any more ideas?

do i maybe need to use the path names thing as described in the open panel project? but that would give me a list of files, not just the folder as a string would it?

sorry, I missed as string


set the_site_folder to (path name of open panel) as POSIX file as text

and


.
set new_file_path to the_site_folder & ":credits.txt"
.

Consider the colon at the beginning of “credits.txt”

ill try that and let you know…

No there are

path name and path names,
you need only the singular without that special form in the Open Panel example

great :smiley: worked perfectly

thanks as always

max

wokay stefan,

here is the thing. your solution works fantastic

  • but there is one more thing… (kinda like steve jobes mate… LOL)

when i open the panel once, and run my action which basically does the on_create_credits_file()

i can no longer open the panel a second time. it just gives me the funk sound… no errors of any kind

any ideas?

I remember, you had this behavior before,
I guess it’s not the call of the handler which opens the panel,
the cause must be the clicked or whatever handler

i have it this way with the clicking:

on clicked theObject
	
	
	if name of theObject is "b_choose_site_folder" then
		
		set_choose_folder()

apples open panel proj has it in a similar way, but it workx :smiley: ?

have you exactly the same conditions, e.g. window “main” is still visible?

yep - all of that is set. ill look at it more close l8r today and let u know.

max

okay. i solved this not opening by fixing a wrong line.

i originally had "hide window “cybwewefae”

but it has to be "close panel “xyzgoaugsfd” (as found in the sample project from AS Studio)

max

:lol: