Applescript works sometimes

Discussion in 'Mac Programming' started by grashapa1, Jun 23, 2008.

  1. macrumors newbie

    Joined:
    Jun 23, 2008
    #1
    I have written an applescript program that seems only to work on certain websites. I am trying to take the pageSource of website and transfer it to excel.

    tell application "Safari"
    open location "http://www.microsoft.com/mac/developers/default.mspx?CTT=PageView&clr=99-21-0&target=b2656752-dbbb-494e-ad09-031d08e7bc8e1033&srcid=cdb9a274-738f-4e4a-9e8c-83feda0485241033&ep=7"
    set pSource to the source of the front document
    end tell
    tell application "Finder"
    activate
    open document file "Sorting Info.xls" of folder "Research Data" of folder "Desktop" of folder "Rich" of folder "Users" of startup disk
    end tell
    tell application "Microsoft Excel"
    activate
    activate object workbook "Sorting Info.xls"
    activate object worksheet "Sheet1"
    set theRange to range "A1:A100" of sheet 1 of active workbook
    set value of active cell to pSource
    end tell

    However, if i usedhttp://www.google.com or http://finance.google.com/finance?q=ABC the data doesn't seem to transfer

    Can anyone help me figure out what is going wrong?

    Also, I would appreciate it if someone could help me figure out how to make one line of the page Source appear as one cell in Excel
     
  2. thread starter macrumors newbie

    Joined:
    Jun 23, 2008
    #2
    After playing with this more, I have learned that if you just type

    tell application "Safari"
    open location "http://finance.google.com/finance?q=ABC"
    set pSource to the source of document 1
    end tell


    you can make the pagesource appear in the results
    However, if you add the display dialogue


    tell application "Safari"
    open location "http://finance.google.com/finance?q=ABC"
    set pSource to the source of document 1
    display dialogue pSource
    end tell

    you get a blank box that pops out
     
  3. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #3
    Add "delay 1" in-between "open location bla bla" and "set pSource to the source of the front document"

    Code:
    open location "http://www.google.com"
    delay 1
    set pSource to the source of the front document
     
  4. thread starter macrumors newbie

    Joined:
    Jun 23, 2008
    #4
    That doesn't solve the problem. I had tried that previously. It doesn't depend on the delay. Somehow the data doesn't seem to be transferring.
     
  5. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #5
    Typical AppleScript weirdness... It works fine for me.

    Does this work?
    Code:
    tell application "Safari"
    	open location "http://finance.google.com/finance?q=ABC"
    	set pSource to the source of document 1
    end tell
    
    tell application "TextEdit"
    	activate
            make new document
    	set text of the front document to pSource
    end tell
     
  6. thread starter macrumors newbie

    Joined:
    Jun 23, 2008
    #6
    safari page source to excel

    That works fine, but I specifically need the pagesource to transfer to excel. I have a bunch of formulas in excel that sort the urls for me. However, the point of this applescript is to allow me to sort through hundreds of companies. Does anyone recommend anything besides applescript? or how should I do this?
     

Share This Page