Skip to content

Repository files navigation

AFK Script

A minimalist instruction language for automating user input at specified times

Downloads

Install

Download the latest release of AFK Script. Unpack the archive on your computer and create a reference in your path environment to it. Now you should be able to run AFKScript in the terminal.

About

A time-based scripting language for automating user tasks.

DescriptionValues
File extension.afk

Command-Line Options

FlagDescription
/cpRun scripts as parallel child processes
/hlHides console log outputs

Instruction Set

Mandatory parameters are specified with "[...]" and optional with "(...)".

InstructionParameter(s)Description
AT(date) (time)Stops the program flow until the specified time has passed
WAIT[milliseconds]Waiting a certain number of milliseconds
CLICKPerforms a mouse click event on the current mouse coordinate on the screen
CLICK[x] [y]Performs a mouse click event on a given coordinate on the screen
KEY[key] (key) (key) ...performs a keystroke event of a single or a number of key combinations.
TYPE[text]Sends a specified character string to standard input or at the current text cursor
LOG[text]Write to the standard output (or console)
READ[variable]Pauses program flow and read from standard-input and store text value in variable.
READ[variable] [text]Pauses program flow, print the text and read from standard-input and store text value in variable.
START[program] (params)Starts a new process similar to using the command prompt
STOP[program]Stops a process if it is running
PAUSEPause program and wait for user interaction
SET[variable] [expression]Store the result of the expression in a variable. Expression could be text, boolean or number,operator or Lua expression.
IF[expression] [label]Jump to label if expression evaluates to a truthy value. Expression could be text, boolean or number,operator or Lua expression.
#(comment)Everything to the right of the hash-tag will be commented out

Formatting

ParameterFormatExamplesparameters significance
date(MM)/(dd)/(yyyy)
(yyyy)-(MM)-(dd)
05/29/2019, 2020-01-31, 02/14 or 043: Exact date
2: Exact day and month every year
1: Exact day every month and every year
time(HH):(mm):(ss)05:50:06, 12:32 or 093: Exact time any day
2: Hour and minutes
1: Hour
text"[string]""Hello, world!"
number[integer]42, 100
booleantrue or false
variable$[name]$shutdownTime, $repeat or $url
label:[name]:start, :end, :L1, :L2
millisecondsSame as number1000, 500
xSame as number405, 316
ySame as number231, 675
key{[key name]} or [text]ENTER, Cancel, F6 or HELLOList or available keys.
expressionany primitive type or Lua expression"hej", 10 + 5, false + "!"
programSame as text
paramsAn array of texts.

Operators

OperatorDescriptionCompatible operand types
==Compare two valuesString, Date, Time, Numeric. Produce boolean
!=Not equalsString, Date, Time, Numeric. Produce boolean
+Adds two numbers or concatenates a string with anything elseString, Date, Time, Numeric. Produce string or numeric
-Subtract one number from anotherNumeric
&&Logical andBoolean. Produce boolean
!Logical notBoolean. Produce boolean
LuaAny Lua expression is a valid expression.

Flags

Flags are set in the beginning of the program to communicate how the program should be run to the interpreter. Flags are prefixed with a @ symbol followed by the flag name.

FlagDescription
@strictCrash when an error occur. Preferred during development or for unsafe scripts

Wildcards

Means that it does not matter which value is on a given position. For example: ##:##:00, will match all time values ending with 00 seconds. 12:05:00 or 05:12:00, but not 14:54:23.

Variables

Variables starts with a prefix $ symbol and a following name. Variable names are case-sensitive, this is important!

Environment Variables

NameDescriptionFormat
$TIMEHolds the current machine timeTime
$DATECurrent dateDate
$ACTIVE_PROGRAMThe title of the currently active program windowString

Labels

Create a label on a new row using a prefix : with a trailing label name. Label names are case-insensitive meaning :Start and :stArt is going to collide and cause an error.

:start # Create a label startLOG "HELLO"GOTO start

Examples

1) First Clicks

AT 17:18
CLICK 532 122
CLICK 140 60
WAIT 10
KEY ENTER
AT 17:45
START """https://www.youtube.com/watch?v=dQw4w9WgXcQ"

This script will (when executed) wait until the current time has passed 17:18:00 today (default) and then preform two click instructions on the screen, wait 10 seconds, send that the key enter was pressed. Wait until 17:45:00 has passed, open up the default browser with a predetermined URL, and then terminate.

2) Variables

# Define $URL
SET $URL"https://twitter.com/williamragstad"
AT 13:00
START ""$URL

This prints the text "Webpage to open: " and prompts for a user input which will be stored inside $URL. Then waits until 13:00 the same day and opens that URL in the standard browser.

3) Reading Input

# Read input and store in $URL
LOG "=== WEB OPENER ==="
READ $URL"Webpage: "
AT 13:00
LOG "Opening up $URL"
START ""$URL

This prints the text "Webpage to open: " and prompts for a user input which will be stored inside $URL. Then waits until 13:00 the same day and opens that URL in the standard browser.

About

A minimalist instruction language for automating user input at specified times

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages