new to mac: Automator / AppleScript keyboard typing / mouse movements

Discussion in 'Mac Programming' started by travel5239, Dec 20, 2009.

  1. travel5239 macrumors newbie

    Joined:
    Dec 15, 2009
    #1
    I just purchased my first Apple computer (entry-level iMac with Snow Leopard), and am beginning to learn the capabilities of Automator, AppleScript, Cocoa, Xcode, etc.. In Windows, I have a script I created in a utility called AutoIt (it allows a basic script to be coded that can execute and control other programs, simulate keyboard typing and mouse movements, and also has basic string/variable manipulation and logic functions).

    What would be the best script/language/tool in OS X to simulate typing into any program? I need this to work with a program that doesn't necessarily have the API coded to allow easy scripting access to its functions, so need to know how to create the actual virtual keyboard presses (and also how to execute the program and pause the script to wait for it to be load and unload at certain points)..

    Any sample scripts that include use of these given functions would be greatly appreciated!

    Thanks!
     
  2. prostuff1 macrumors 65816

    prostuff1

    Joined:
    Jul 29, 2005
    Location:
    Don't step into the kawoosh...
    #2
    I don't mean to sound harsh or anything, but that is FAR to little information to go on. It would help greatly if we knew what you were trying to do with Automater, appleScript, etc. From the vague description of what you gave it seems that the aforementioned should work. There are a lot of examples out there that you can find by simply googling what you are looking for.
     
  3. travel5239 thread starter macrumors newbie

    Joined:
    Dec 15, 2009
    #3
    Here's the basic logic:

    - execute a program and wait for it to open and be ready
    - send a sequence of keystrokes (with delays I'll set at certain times to allow a few moments for the program to perform its own tasks like open files, etc)
    - after a certain keystroke to launch a process, wait until the new window that the program pops up closes (this is when that process ends)
    - send a couple keystrokes to close the program

    This will repeat in a loop with a couple of differences in the keystrokes sent each time - I can figure out the string manipulation and for or while loop out, just am curious about the code to send keystrokes and sense when the desired program is open, and when the window closes. If you could point me to a reference on the specific functions or events, I could probably figure it out from sample code (I just started researching the wide array of Apple developer and scripting options so it'll probably be a little while before I come across the specifics). (I could also provide a sample script in AutoIt if anyone has used it in windows..)
     
  4. Caleb531 macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #4
    I only have experience with Automator and Applescript, but it sounds like, from the steps you've described, this can be done with simple Applescript.


    To delay between actions, use this. Replace that number with however many seconds for the delay (decimals are accepted)
    HTML:
    delay 1.5
    To simulate keystrokes, use this. Just replace "o" with the character and replace command with either shift, option, or control (or a combination)
    Code:
    tell application "System Events"
    	keystroke "s" using {shift down, command down}
    end tell
     
  5. travel5239 thread starter macrumors newbie

    Joined:
    Dec 15, 2009
    #5
    Thanks! I'll try that when my new iMac arrives!

    Is AppleScript just as easily capable of executing a program and pausing until it's up and running (and also sensing when a window in that program changes - or when that window has certain text printed on it by its program)?
     
  6. Caleb531 macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #6
    It depends. Some applications have more applescript support than others. I know all the Apple pre-installed apps do, and I know the Microsoft Office mac apps do as well. However, many third-party apps vary when it comes to applescript support. There are also some commands that will work globally, no matter which app you're using (copy, paste, delay, etc.)

    There is this great series of video podcasts on iTunes for AppleScript and Automator, which has taught me a lot. It will teach you what you need to know about AppleScript.

    Meanwhile, you can use the bits of script I've provided in my previous post.

    If you have any more questions, feel free to email me.
     

Share This Page