Applescript+Cocoa URL source stealing mania!

Member
Posts: 102
Joined: 2005.01
Post: #1
I + My friend are writing a program with Applescript and Cocoa.
here is what happens
applescript calls a method with a parameter/argument that contains a URL

my cocoa program takes the URL loads it into a webview and gets the source code, then sends that back in a string varible

my cocoa program has control over one inteface object. a webView for loading the url then retriving the source

here is what i have so far.. its a mess

appControl.h


Code:
/* appControl */

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>

@interface appControl : NSObject
{
    IBOutlet id webView;
}

- (NSString *)Source;

- (void)getCode;
- (IBAction)loadCodeFromURL:(NSString)inString;
@end



appControl.m

Code:
#import "appControl.h"
#import <WebKit/WebKit.h>
#import <WebKit/WebView.h>
#import <WebKit/WebDocument.h>

@implementation NSApplication (ASKAFullScreen)

- (void)getCodeh
{
}


- (IBAction)loadCodeFromURL:(NSString *)inString
{
    
    
    NSURL *URL = [NSURL URLWithString:inString];
    
    [webView setFrameLoadDelegate:self];
    
    WebFrame *mainFrame = [webView mainFrame];
    
    [mainFrame loadRequest:[NSURLRequest requestWithURL:URL]];
    
    
    
    WebFrame *mainFrame = [webView mainFrame];
    
    id documentRepresentation = [[mainFrame dataSource] representation];
    
    if ([documentRepresentation canProvideDocumentSource]){
        [out setStringValue: [documentRepresentation documentSource]];
    }
    else    {
    //    NSRunAlertPanel(@"Wait", @"Page not done loading", @"Ok", nil, nil);
    }
}

- (NSString *)Source
{
    return @"Test";
}

-(void)dealloc
{
    [super dealloc];
}


@end


i really dont know how to do any of this...

grammars fixed?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
This message is utterly incomprehensible. The "Preview Post" button is there for a reason. Please use it, read what you've written before posting it, and correct errors such as stopping in the middle of a sentence. Rolleyes

- Alex Diener
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #3
So what's the question? Does what you have work?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #4
The question is how should i do this...

it is going to reqire only ONE method so it can return a value back to applescript but its also going to require a delagate method that fires when the webView finishes loading. so im lost....
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #5
not exactly answering your question, but couldn't you just get the source by saying...
Code:
NSString *source = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
where urlString is the url?

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #6
I dont see that in my code....

what we did before was have applescript push a button that used cocoa to load a webview

then it pushed a button that got the source of the web view if it failed it tried again

it repeated until it got the source code

and that works but its horribly innefficient
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #7
I don't know much about applescript, but to get the source, you would do the section of code mentioned above.

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #8
Wait


i thouhgt you said you COULDNT get it just by doing that, and that was how i got it before... misread what you said......thanks taht makes it a jilliontimes easier
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Applescript: Get message content from Mail Yoda 2 4,303 Apr 1, 2006 11:52 AM
Last Post: Yoda
  Good Time For Applescript? Nick 1 2,608 Jun 12, 2005 07:27 AM
Last Post: Andrew
  Applescript-NSToolbar Coin 0 2,362 Mar 14, 2005 12:06 AM
Last Post: Coin