Tabbed Webview

Does anyone know if you can create tabs with Webview? I’d like to have two buttons at the top of my Webview screen, and have these act as two seperate tabs for webpages so that I may go back and forth between the two and have them saved there. Is that even possible with AppleScript Studio?

Use NSTabView and create a new WebView instance for each tab you create.

I’m pretty new to AppleScript, how do I create a NSTabView. Also, I have to make sure that when I look up something on one website and switch to another tab for another website, that when I switch back to the first website, it’s not actually retrieving the website again because I’m creating this for a website that charges me money each time I do a lookup on it.

Just like you would any other UI element in Interface Builder, by dragging one into your window. You may want to start here:

http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/index.html

Read the guide and do the tutorials. When you’re done, go here:

http://developer.apple.com/documentation/AppleScript/Reference/StudioReference/sr4_container_suite/sr_container.html
and
http://macscripter.net/articles/462_0_10_0_C/

Additionally, several Studio of the examples included with the developer tools demonstrate how to use tab views.

thank you mikey-san … found what I needed in there. I’ve actually been looking for a walk-through tutorial site like that … I never thought to actually check Apple’s developer website.

ok, I thought I had it working but apparently I don’t. I can’t get the WebView to load in Tab View.

Here’s my script.

on clicked theObject
	
	GetURL()
end clicked

on end editing theObject
	GetURL()
end end editing

on GetURL()
	
	tell window "main"
		
		set theURL to "http://www.google.com" as text

		try
			set newString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
			set URLWithString to call method "URLWithString:" of class "NSURL" with parameter newString
			set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
			
			set mainFrame to call method "mainFrame" of object (view "browser1" of tab view "Tab1")
			
			call method "loadRequest:" of mainFrame with parameter requestWithURL
		end try
	end tell
end GetURL

My tabview is called “TabView” and Tab 1 = “Tab1”, and the WebView in Tab 1 is called “browser1” (in case that wasn’t immediately obvious). What am I doing wrong here?

Also, is there a wy to add more tabs than 2? The only way I could think of would be to add more buttons at the top of my tabbed webview and have them work as tabs, but they don’t look the same as Tab 1 and Tab 2.

yes, just look at the inspector to figure out how to add more tabs. As for oyur coding you have to also refernece which tab view item its in. so something like

set mainFrame to call method "mainFrame" of object (view "browser1" of tab view item "view1" of tab view "Tab" of window "main")

Thanks Hendo, that helped me find out how to make more tabs, but I’m still having trouble. here’s how i wrote that line to fit my code:

set mainFrame to call method "mainFrame" of object (view "browser1" of tab view item "tabView" of tab view "Tab1" of window "main")

browser1 = name of the WebView in Tab 1
Tab1 = name of Tab 1 (obviously)
tabView = name of Tab View window

And I tabView set like this:
in the inspector:
selected “awake from NIB”
selected in Tab View “will select tab view item”

And in File Inspector, I clicked on the “launched” in the application section

Do I need to add more code to my script to make it work with tab views? I tried my code with just a WebView window and it works fine, so whatever’s going wrong, it’s the tab view. Any suggestions?

I’ve been playing around with this code for hours, changing where I put the Tab View codes, changing the names of the codes. I’ve been able to figure out how to have different text boxes in my tabs show different texts based on my script, so tab view works fine for that but not for Web View. Has anyone ever actually created Web browsers in the Tab View? I’ve tried googling for examples and I don’t see any. Maybe it’s not possible?

on clicked theObject
	GetURL()
end clicked

on end editing theObject
	GetURL()
end end editing

on GetURL()
	
	tell tab view 1 of window 1
		set theURL to "http://www.google.com" as text
		
		try
			set newString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
			set URLWithString to call method "URLWithString:" of class "NSURL" with parameter newString
			set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
			set mainFrame to call method "mainFrame" of object (view "browser1" of tab view item "tab1")
			
			call method "loadRequest:" of mainFrame with parameter requestWithURL
			
		end try
	end tell
end GetURL

Thank you for your reply, Jacques, but I’m getting this error message:

NSReceiverEvaluationScriptError: 4 (1)

Here’s what I got now:

on clicked theObject
	
	GetURL()
end clicked


on end editing theObject
	GetURL()
end end editing

on GetURL()
	tell tab view 1 of window 1
		set theURL to "http://www.google.com" as text
		set current tab view item to tab view item "tab1"
		
			set newString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
			set URLWithString to call method "URLWithString:" of class "NSURL" with parameter newString
			set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
			set mainFrame to call method "mainFrame" of object (view "browser1" of view of tab view item "tabView" of tab view "Tab1" of window "main")
			
			call method "loadRequest:" of mainFrame with parameter requestWithURL
			
	
	end tell
end GetURL

I added the

set current tab view item to tab view item "tab1"

because it kept opening up on tab 2 for some reason, and this worked for making it automatically choose tab 1 when i press my button. Even without adding that, I’m still getting the same error message so I know that new addition isn’t the problem. I’m probably making a really big rookie mistake here, but I can’t figure out what it is. I even tried copying and pasting your script exactly how you wrote it in there and still no luck.

thank you Jacques, that worked perfectly. I still learning by copying and pasting what I’m seeing from others, so whenever I make any changes, I get confused about how to reference things properly. Thanks!