[MAC OS X] WScript.Shell Alternative

Does anyone know of an alternative to WScript.Shell that works for Mac OS X?
For anyone who doesn't know, this allows you to send key strokes (among
other things) to other programs without having the other program explicitly
written to accept such input. Here is an example script using WScript.Shell

-----[code]-----

require "win32ole"

shell = WIN32OLE.new("WScript.Shell")
shell.AppActivate("Command Prompt")
shell.SendKeys("cls{ENTER}")
shell.SendKeys("dir{ENTER}")
shell.SendKeys("echo Hello, World!{ENTER}")

-----[/code]-----

Thanks for any help.

···

--
--- Shane Emmons <semmons99@gmail.com>

There are a number of things you need to do:

1. Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane. This allows you to send keystrokes (and any GUI related input) to apps not written to accept them.

2. Send the keystrokes by using applescript or some other osascript language. RubyCocoa can provide this osascripting bridge with Ruby, but I have no experience of this.

3. Using applescript :frowning: this will give you an idea (over half the lines are error handling):

on run argv
  activate application "Preview"
  tell application "System Events"
    get system attribute "sysv" -- argv
    if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
      if UI elements enabled then
        tell application process "Preview"
          -- GUI Scripting statements:
          keystroke "f" using {command down}
          set search_string to item 1 of argv
          keystroke search_string
        end tell
      else
        beep
        display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
        if button returned of result is "OK" then
          tell application "System Preferences"
            activate
            set current pane to pane "com.apple.preference.universalaccess"
          end tell
        end if
      end if
    else
      beep
      display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
    end if
  end tell
end run

but the key lines are the GUI scripting statements.

This example will open the Preview app and do a search for some text supplied on the command line. (Preview lacks any real applescript support). This script is then run with the command line:

osascript path_to_script word_to_search_for

While this isn't quite what you want it should give you a head start or some ideas.

Dave.

···

On 7 Sep 2006, at 16:55, Shane Emmons wrote:

Does anyone know of an alternative to WScript.Shell that works for Mac OS X?
For anyone who doesn't know, this allows you to send key strokes (among
other things) to other programs without having the other program explicitly
written to accept such input. Here is an example script using WScript.Shell

-----[code]-----

require "win32ole"

shell = WIN32OLE.new("WScript.Shell")
shell.AppActivate("Command Prompt")
shell.SendKeys("cls{ENTER}")
shell.SendKeys("dir{ENTER}")
shell.SendKeys("echo Hello, World!{ENTER}")

-----[/code]-----

Thanks for any help.

--
--- Shane Emmons <semmons99@gmail.com>

Shane Emmons wrote:

Does anyone know of an alternative to WScript.Shell that works for Mac OS X?

Wouldn't Expect work on OS X too?

David Vallner

Shane Emmons wrote:

Does anyone know of an alternative to WScript.Shell that works for Mac OS X?

Wouldn't Expect work on OS X too?

Pretty sure he means GUI apps.

···

On Sep 7, 2006, at 8:52 PM, David Vallner wrote:

David Vallner

Yeah, I meant GUI apps. I ended up just using applescript(cringe).

···

On 9/7/06, Logan Capaldo <logancapaldo@gmail.com> wrote:

On Sep 7, 2006, at 8:52 PM, David Vallner wrote:

> Shane Emmons wrote:
>> Does anyone know of an alternative to WScript.Shell that works for
>> Mac OS X?
>
> Wouldn't Expect work on OS X too?
>
Pretty sure he means GUI apps.

> David Vallner
>

--
--- Shane Emmons <semmons99@gmail.com>