Applescript to paste text into safari Problem

Discussion in 'Mac Programming' started by SChaput, Jul 28, 2010.

  1. SChaput macrumors regular

    Joined:
    Jul 2, 2008
    Location:
    United States
    #1
    I'm writting a quick apple script to try and paste some user inputed information into safari. Below is my code:
    Code:
    
    set thePrefix to ""
    set theNumber to ""
    set theIcon to note
    display dialog "Please Enter The URL:" default answer ""
    set theNumber to text returned of result
    set the clipboard to theNumber
    
    tell application "Safari"
    	make new document at end of documents
    	activate "Safari"
    	set URL of document 1 to "http://www.facebook.com" 
    	keystroke "v" using {command down} 
    
    end tell
    
    I'm trying to copy the user input to the clipboard, which works, but when i try to paste it into the URL i get the error:
    Expected end of line but found identifier

    Can anyone shed any light on this?

    Thank you!
     
  2. ccamelot macrumors member

    ccamelot

    Joined:
    Feb 21, 2010
    Location:
    Poland
    #2
    Some light...

    Hi,

    here you go:

    Code:
    set thePrefix to ""
    set theNumber to ""
    set theIcon to note
    display dialog "Please Enter The URL:" default answer ""
    set theNumber to text returned of result
    
    tell application "Safari"
    	activate
    	make new document at end of documents
    	set URL of document 1 to "http://www.facebook.com/" & theNumber
    end tell
    
    keystroke is a part of "System Events" dictionary, then you have to call it this way:
    Code:
    tell application "System Events"
    	tell process "Safari"
    		keystroke "v" using {command down}
    	end tell
    end tell
    
     

Share This Page