Text fields & Tabs & Boxes

what am I doing wrong. Im getting the “NSReceiverEvaluationScriptError: 4 (1)” error. :mad:


if name of theObject is "fileBtn" then
		set theFilePath to POSIX path of (choose file without invisibles)
		set content of text field "fileToImport" of tab view "tabView" of window "mainWindow" to theFilePath
end if

Thanks

You must reference the specific tab view item of the tab view that the text field is in…

set content of text field "fileToImport" of tab view "tabView" of window "mainWindow" to theFilePath

…should be…

set content of text field "fileToImport" of tab view item "someTabViewItem" of tab view "tabView" of window "mainWindow" to theFilePath

j

yay! That works, now…

why doesn’t this work?


if (selected tab view item of tab view "tabView" of window "mainWindow") is "importData-Tab" then
			set {visible of box "chooseInputType-Box" of tab view item "importData-Tab" of tab view "tabView" of window "mainWindow", visible of box "chooseExportType-Box" of tab view item "importData-Tab" of tab view "tabView" of window "mainWindow"} to {false, false}
end if

You might try something like this:

if (selected tab view item of tab view "tabView" of window "mainWindow") is "importData-Tab" then
	tell window "mainWindow"
		tell tab view item "importData-Tab" of tab view "tabView"
			set visible of box "chooseInputType-Box" to false
			set visible of box "chooseExportType-Box" to false
		end tell
	end tell
end if

There may be something that I have overlooked. Wouldn’t be the first time.

Once you get a handle on correctly referencing interface objects, Studio does get easier. Stick with it.

Hope this helps,
Brad Bumgarner, CTA

Nope, didn’t work. Referencing objects in Stuido is difficult. Is there a cheat sheet anywhere that has the type of object and it’s reference? Any ideas on hiding a box and contents within a tab view?

When I’m in Interface Builder (IB) creating my interface I will jot down the name and type (i.e., button, text field, etc.) of each object that I will be referencing in code. At the top of my script I’ll enter this information in a comment box so that I always have quick access to the names of each object.

As to referencing each object, think in terms of “parent/child” relationships. If text field “A” is in box “B” and box “B” is in tab view item “C” and tab view item “C” is in tab view “D” and tab view “D” is in window “E” then to reference text field “A” you’d use the following:

set myVar to the contents of text field “A” of box “B” of tab view item “C” of tab view “D” of window “E”

Remember: computers are stupid – you have to tell them exactly what to do! :smiley:

A good source of information is the Applescript Studio Reference Guide. I’ve said it before, I “live” in that guide. I am always refering to it. You can get to it by going to Xcode’s Help Menu → Documentation → Search Groups (on the left side of the dialog) → Applescript → Tools → Applescript Studio Reference Guide (html – if you want to view it in the same window).

Hope this helps,
Brad Bumgarner, CTA