Applescript - param to keystroke

Discussion in 'Mac Programming' started by joppze, Jun 30, 2010.

  1. joppze macrumors newbie

    Joined:
    Jun 30, 2010
    #1
    Hello,

    Im trying to write a applescript that will take arguments (in my case a string of words) and them print them out in the desired application as keystrokes.

    Right now the code looks like this:

    PHP:
    on run searchbar
        set test to 
    (item 1 of searchbar)
        
    tell application "System Events"
            
    tell application "myapp" to activate
            keystroke test
        end tell
    end run
    I don't know if this is the right way to code it, but I found this pretty much by searching on google. Anyhow, it doesn't work..

    So my question is how I should do? I simply want the applescript to take one param that contains a string of words. Then print the entered string out in my app.

    Thanks in advance!

    /Joppze.
     
  2. ccamelot macrumors member

    ccamelot

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

    Hi,
    plase check this thread (last post).

    It works for me:
    Code:
    on doit(withThisText)
    	tell application "TextEdit" to activate
    	tell application "TextEdit" to make new document
    	tell application "System Events" to keystroke withThisText
    end doit
    
    doit("Hello World!")
    all best
    Les
     
  3. joppze thread starter macrumors newbie

    Joined:
    Jun 30, 2010
    #3
    Thanks for the answer!

    But it wasn't exactly what I was looking for.

    PHP:
    on run searchbar
        tell application 
    "System Events"
            
    tell application "myapp" to activate
            key code 37 using command down
            keystroke searchbar
            delay 
    (1)
            
    keystroke return
            
    keystroke tab
            delay 
    (1)
            
    keystroke tab
            keystroke 
    return
            
    key code 4 using command down
        end tell
    end run
    As you can see I want the script to take an argument and then print it out in the desired area using keystroke. But I cannot seem to get it to work..

    Any idéas?
     
  4. ccamelot macrumors member

    ccamelot

    Joined:
    Feb 21, 2010
    Location:
    Poland
    #4
    I'm sorry if I do not fully understand your request. From where your argument comes from? Commandline? Another script? User input?
     
  5. joppze thread starter macrumors newbie

    Joined:
    Jun 30, 2010
    #5
    I wanna give the script an argument from the commandline and the output the given string (from the command line) with keystroke command (or output it on any other way) into my application.
     

Share This Page