Well, I decided to take on a new programming experience. I am now working with Xcode.
I have a mini web brower and a couple of menu items from the menu bar. How do I make it so that when I click a menu item it will load a specific url?
How do I tell it to go to a URL just by clicking a button?
Use something like this to load a URL:
call method "URLWithString:" of class "NSURL" with parameter ("http://www.google.com")
call method "requestWithURL:" of class "NSURLRequest" with parameter (result)
call method "loadRequest:" of (call method "mainFrame" of object (view "yourView" of window "yourWindow")) with parameter result
Forgive my noobie response but, where do I put that in my new project?
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
Are you using AppleScript or Objective-C?
Objective-C.
EDIT: I used Interface builder to layout a simple web browser. How do I get it to run? I click run and build and this is what I get the following. It says it exited normally but I want it to stay open until I close it.
http://www.geocities.com/peejavery/xcode.jpg
If someone is up to it, can you just make a cocoa app with a webview, textbox, and button? Click the button to load the url from the textbox???
Okay, I am switching to AppleScript in Xcode. How do I set that up with the main sub?
The script below allows the text field to be read either on ‘end editing’ or when the associated button is clicked. The latter really isn’t necessary, but it’s there anyway.
I just used the syntax described by Bruce. Hope it’s of use.
on clicked theObject
GetURL()
end clicked
on end editing theObject
GetURL()
end end editing
on GetURL()
set tmpURL to contents of text field "URL" of window "Main"
try
set URLWithString to call method "URLWithString:" of class "NSURL" with parameter tmpURL
set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
set mainFrame to call method "mainFrame" of object (view "myWeb" of window "Main")
call method "loadRequest:" of mainFrame with parameter requestWithURL
on error the_error
log the_error
end try
end GetURL