Rebol/Windows Macro Maker - Autopilot.r
[1/4] from: tbrownell::shaw::ca at: 31-Mar-2002 0:44
REBOL [
Title: "LFReD AutoPilot"
Date: 31-Mar-2002
File: %autopilot.r
Author: "Terry Brownell"
Version: 1.0
Needs: ["Windows with Script Host, Rebol/Pro or /command"]
Rights: "Copyright (C) Terry Brownell 2002"
Note: {
This script is free; you can redistribute it and/or modify it under the terms of the
GNU General Public License.
Instructions:
1. Create a folder and place this script inside.
2. Create a .txt file with your macro (sample below) and place inside the same folder.
3. "Do" this script, then call the function "AutoPilot" and the macro .txt file.
There are four basic commands - Activate, Launch, Wait and Type.
Activate - Focuses a running app.
Launch - Launch a new app.
Wait - Pause in milliseconds. (1000 = 1 second)
Type - Enter keystrokes.
}
]
;----------------AUTOMATE
AutoPilot: func [inpu][Macro1: rejoin [to-file inpu ".txt"] AutoPilot: read macro1
AutoPilotCode: copy []
autopilot: parse autopilot none
insert AutoPilotCode rejoin [{Set WshShell = WScript.CreateObject("WScript.Shell")} newline]
AutoPilotA: {WshShell.AppActivate }
AutoPilotR: {WshShell.Run }
AutoPilotS: {WScript.Sleep }
AutoPilotT: {WshShell.SendKeys }
foreach [com att]autopilot [if com = "Activate" [append autopilotcode rejoin [AutoPilotA
{"} att {"} newline ]] if com = "Launch" [append AutoPilotCode rejoin [AutoPilotR {"}
att {"} newline]] if com = "Wait" [append AutoPilotCode rejoin [AutoPilotS att newline]]
if com = "Type" [append AutoPilotCode rejoin [AutoPilotT {"} att {"} newline]]]
write %autopilot.vbs AutoPilotCode
call "autopilot.vbs"
wait 3
delete %autopilot.vbs
]
;----------------------------
;Below is a sample macro that will launch notepad, wait 3 seconds, type "Hello World,
wait 1 second and type "Again"... place into a .txt file in the same folder, then run
it as... Autopilot "myMacrofile.txt"
;Activate "Notepad" type "^n" Wait 3000 Type "Hello World" Wait 1000 Type " Again."
[2/4] from: james:mustard at: 1-Apr-2002 9:38
As an aside - for those without pro or command you can do the following as a
replacement for call:
browse %autopilot.vbs
This will launch the script WITHOUT launching the browser - depending on
your security settings and whether you have the Windows Scripting Host
installed.
Please also note that the original function needs to launch as
Autopilot "myMacrofile"
;rather than Autopilot "myMacrofile.txt" due to the Macro1 line which
appends txt again.
James.
[3/4] from: tbrownell:shaw:ca at: 31-Mar-2002 21:57
Open source, ya gotta love it. Thanks for the bug report ;)
TB
[4/4] from: james:mustard at: 2-Apr-2002 13:00
Hi Terry,
I mangled things a bit and rearranged other bits ;-)
The example at the end demonstrates the Force command which can take 1 or 2
parameters.
AutoPilot: func [inpu][
AutoPilot: read/lines to-file inpu
AutoPilotCode: {Set WshShell = WScript.CreateObject("WScript.Shell")}
AutoPilotA: {WshShell.AppActivate "###1"^/}
AutoPilotR: {WshShell.Run "###1"^/}
AutoPilotS: {WScript.Sleep "###1"^/}
AutoPilotT: {WshShell.SendKeys "###1"^/}
;please note that some apps have 2 names - one for launch and 1 for
userspace
;Microsoft Word is one such example. Winword to launch, Microsoft Word for
userspace.
AutoPilotF: {
if not WshShell.AppActivate("###1") then
WshShell.Run("###2")
do while not WshShell.AppActivate("###1")
WScript.sleep 10
loop
end if
}
rj: func [cmd srch dat][AutoPilotCode: join AutoPilotCode replace/all
copy cmd srch dat]
foreach syl AutoPilot [
syl: to-block syl
switch length? syl [
2 [
com: to-string first syl
att: second syl
if com = "Activate" [rj AutoPilotA "###1" att]
if com = "Launch" [rj AutoPilotR "###1" att]
if com = "Wait" [rj AutoPilotS "###1" att]
if com = "Type" [rj AutoPilotT "###1" att]
if com = "Force" [replace rj AutoPilotF "###1" att "###2"
att]
]
3 [
com: to-string first syl
att: second syl
att2: third syl
if com = "Force" [replace rj AutoPilotF "###1" att "###2"
att2]
]
]
]
write %autopilot.vbs AutoPilotCode
browse %autopilot.vbs ;call
wait 3
delete %autopilot.vbs
]
;----------------------------
;Below is a sample macro that will launch Word (if it exists) type
something, then launch notepad,
;wait 3 seconds, type "Hello World, wait 1 second and type "Again"
write %myMacrofile.txt {Force "Microsoft Word" "Winword"^/Type "This is
microsoft word!"^/Force "Notepad" ^/Type "^n" ^/Wait 3000 ^/Type "Hello
World" ^/Wait 1000 ^/Type " Again."^/}
Autopilot "myMacrofile.txt"