Show file path

Hi

i have a script as follows:

set theFile to (choose file with prompt “Choose your file…”) as text

how would I go about to show the file path that theFile gets, in text? I would like to have it appear next to the browse button.

Hi,

use a TextField or a Path Control element.

Note: Unlike AppleScript itself most of the control elements in AppleScript Studio expect POSIX (slash separated) paths

how would I go about to show the file path in the text field? I am noob at interface builder

Please read AppleScript Studio Programming Guide especially the part Currency Converter Tutorial

thank you. I came up with this:

on clicked theObject
set filePath to (choose file with prompt “Choose ROM file…”) as text

tell box of theObject
	set contents of text field "showPath" to (POSIX path of filePath) as text
end tell

end clicked

i have both the Browse button and the text field in a box

I get no errors, but also nothing appears in the text field. :frowning:

theObject is obviously a button, so there cannot be a box of this button
The box is probably a child element of a window, which contains the text field.
The reference should look like


on clicked theObject
	set filePath to POSIX path of (choose file with prompt "Choose ROM file...")
	set string value of text field "showPath" of box "box" of window "main" to filePath
end clicked

of course the box and the window must be named properly in the AppleScript tab of the inspector window

thank you stefan, it works!

however, when I place my box in a Tab View, I get problems.

I changed
set string value of text field “showPath” of box “box” of window “main” to filePath

to

set string value of text field “showPath” of box “box” of tab view “tab” of window “main” to filePath

but get errors when trying to run:

cant set <> of <> “tab” of window “main” to /my/file/path

any idea why it is trying to set my box to the filepath and not the text field?

you have to specify a tab view item


.
set string value of text field "showPath" of box "box" of tab view item "myItem"  of tab view "tab" of window "main" to filePath
.

thank you stefan. now it works perfectly.

i have one last thing that troubles me

i have a combo box (or a dropdown menu as id call it) in my app.

I want a button next to it, to run different code depending on the item selected in the menu.
i was thinking of something like this

set listValue to --------------------
if listValue is equal to "My first Menu Item"
then
Code for my first menu item

else if listValue is equal to "My second Menu Item"
then
Code for my second menu item
end if

the ----- is because I don’t know how to get the value of the item selected.
if I try "set listValue to contents of combo box “box”,
i cant even compile it:/

Folks, please read the documentation of AppleScript Studio. All terms are described extraordinarily detailed.
Contents of combo box “combobox” is correct but like the other example you must specify the whole reference to the root object (the window).

Combo Box Reference

Sorry, stefan
I actually spent alot of time reading that document before I posted, but when I tried to run my code, the computer couldn’t make head or tails of it, so I assumed it was old or something

I now realised I had made a .scrpt item instead of .applescript, so now everything runs. thank you.