Open panel to set input in two fields.

Ok, here’s the set up:

Two text fields. One for input file, the other for output directory. Both with a browse button to set the contents of the text field.

This is the issue I’m running into:

I can test on click theObject for which browse button is clicked. But you must call on panel ended to set the result from the open panel and you can’t do this within any other event block.

so things like (pseudo code):

on clicked theObject
	display panel
	if theObject is browseOne
		on panel ended
			set result to textFieldOne
		end panel ended
	end if
end clicked

It also doesn’t pause at the panel event waiting for a return…so the following doesn’t work eithe r(psuedo code)

on clicked browseOne
	display open panel
	set textFieldOne to result
end on clicked

on panel ended
	set result to selected file
end panel ended

as it will say that the result is not set.

Any leads on what to do in this situation?

Try something like this:

on clicked theObject
	if theObject's name is "blah" then
		tell open panel
			set can choose directories to true -- or false
			set can choose files to true -- or false
			set allows multiple selection to false -- or true
		end tell
		
		display open panel
	end if
end clicked

on panel ended theObject with result withResult
	-- The open and save panels set `withResult` to 0 if the user canceled
	if withResult is 1 then
		set content of text field "something1" of window "whatever" to (path name of open panel)
		set content of text field "something2" of window "whatever" to (path name of open panel)
	end if
end panel ended

Thank you bruce, but wouldn’t that set textField 1 & 2 to the same value?

The user would be entering two different values at two different times, one being output and one being input.

I solved it by creating a global browseButton variable and toggling it from “output” to “input” depending on which button was click.

Then within the on end panel block, I did a conditional testing for this toggle and setting the appropriate text field accordingly.

Sorry krunk, I misunderstood you. This sounds similar to this thread: ‘printout’ window

It sounds like you used something like this, which is good. :slight_smile:

global usingOpenPanelFor

on clicked theObject
	if theObject's name is "input" or theObject's name is "output"  then
		set usingOpenPanelFor to theObject's name
	
		tell open panel
			set can choose directories to true -- or false
			set can choose files to true -- or false
			set allows multiple selection to false -- or true
		end tell
		
		display open panel
	end if
end clicked

on panel ended theObject with result withResult
	-- The open and save panels set `withResult` to 0 if the user canceled
	if withResult is 1 then
		set content of text field usingOpenPanelFor of window "whatever" to (path name of open panel)
	end if
end panel ended


Hi Krunk,

krunk wrote:

Please view this thread: http://bbs.applescript.net/viewtopic.php?id=18547

In my case, I used the “on end editing” handler rather than the “panel ended” to register the changes in the text field of my attached panel. jobu suggested using “on changed” handler and that should work too.

As regards pausing the panel to wait, I used a global boolean flag that could be tested and based on the existing condition of the flag, allows my program to exit the attached panel so that the edited text could be processed.

I am not sure if we have the same problem, Still, I do hope that the above could give you some leads.

archseed :slight_smile: