Requires latest version (v3.5.3+) - Made by /u/shirtandtieler
My motivation in creating this library was wanting to create a way to seamlessly integrate custom
functions with AutoTouch. After many hours of hard work, I have created a whole spectrum of different
useful functions. If you're familiar with Python, any similar naming conventions are no coincidence :)
Enjoy! (And contact me on reddit if you have any questions/problems/suggestions)
As far as installing it goes, there are 0 risks. I have thoroughly tested the install/uninstall process dozens of times and have never encountered any problems.
In the case that the uninstall feature isn't working, just reinstall AutoTouch and it'll completely remove Functions+.
As far as using the functions go, the only function that could possibly cause some damage is exe - but that's only because you're running terminal commands. As long as you're not running commands to remove all files on your device, you'll be perfectly safe :)
For either a suggestion or a bug, shoot a message to /u/shirtandtieler on Reddit.
I'm totally open to (and would love) suggestions for new functions to add, but only if they are useful/practical -though, if you're doubting the practicality of it, still send it to me anyway :)
Functions
Back to top
getActiveApp()
Gets the AppID of the currently active app
Parameters
Parameter
Type
Description
None
None
None
Return values
Type
Description
String
The full app identifier
Example(s)
-- while in the AutoTouch app
log(getActiveApp())
-- prints 'me.autotouch.AutoTouch.ios8' to the log
Back to top
isBool(input)
Checks if the input is a boolean
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is a boolean, otherwise false
Example(s)
t = true
f = false
if isBool(t) and isBool(f) then
log("Both variables are booleans!") -- gets logged
end
Back to top
isNil(input)
Checks if the input is nil (a.k.a. null, None, nothing, etc.)
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is nil, otherwise false
Example(s)
-- example function that doesn't return anything
function test(x, y)
local z = x + y
end
set2nil = test(1, 2)
if isNil(set2nil) then
log("The test function returned nil!") -- gets logged
else
log("The test function has a return value!") -- does NOT get logged
end
Back to top
isNotNil(input)
Checks if the input is not nil
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is NOT nil, otherwise false (i.e. the input IS nil)
Example(s)
-- example function that doesn't return anything
function test(x, y)
local z = x + y
end
set2nil = test(1, 2)
if isNotNil(set2nil) then
log("The test function has a return value!") -- does NOT get logged
else
log("The test function returned nil!") -- gets logged
end
Back to top
isNum(input)
Checks if the input is a number
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is a number, otherwise false
Example(s)
integer = 3
float = 3.14159
hexadecimal = 0xbadb07
if isNum(integer) and isNum(float) and isNum(hexadecimal) then
log("All 3 variables are numbers!") -- gets logged
end
Back to top
isStr(input)
Checks if the input is a string (i.e. text)
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is a string (i.e. text), otherwise false
Example(s)
objects = {0xca7d0e, "fat horse"}
if isStr(objects[1]) then
log(objects[1] .. " is a string.") -- does NOT get logged
elseif isStr(objects[2]) then
log(objects[2] .. " is a string!") -- gets logged
end
Back to top
isTable(input)
Checks if the input is a table (a.k.a. array, list)
Parameters
Parameter
Type
Description
input
Any (String, Table, Number, Boolean, Nil)
The object you want to check
Return values
Type
Description
Boolean
true if the input is a table, otherwise false
Example(s)
realTable = {1, false, "hello!"}
stringTable = "{true, 'ohai', 66}"
if isTable(realTable) then
log("realTable is a real table!") -- gets logged
end
if isTable(stringTable) then
log("stringTable isn't a table, it's a string!") -- also gets logged
end
Back to top
isin(x,y)
Checks if x is a substring or subelement of y
Parameters
Parameter
Type
Description
x
Any (String, Table, Number, Boolean, Nil)
The substring/subelement
y
Any (String, Table, Number, Boolean, Nil)
The larger object that you want the function to parse
Return values
Type
Description
Boolean
true if x is in y, otherwise false
Example(s)
-- Example 1: (String, String)
if isin("o", "AutoTouch") then
log("There's an 'o' in 'AutoTouch!")
-- since there is an 'o' in the word 'AutoTouch', this gets logged
end
-- Example 2: (String, Table)
itemToCheck = "baby"
pets = {"dog", "cat", "bird"}
if isin(itemToCheck, animals) then
log("A baby is a pet too!")
-- since "baby" is not in the table, this does NOT get logged
end
Back to top
isnotin(x,y)
The inverse of 'isin' - made as an easier way to type than 'not isin(,)'
Parameters
Parameter
Type
Description
x
Any (String, Table, Number, Boolean, Nil)
The substring or subelement
y
Any (String, Table, Number, Boolean, Nil)
The larger object that you want the function to parse
Return values
Type
Description
Boolean
true if x is NOT in y, otherwise false
Example(s)
-- Example 1: (Number, String)
birth_year = 1992
birthday = "My birthday falls on August 14th"
if isnotin(birth_year, birthday) then
log("No details on the birth year in the birthday description text!")
-- gets logged since the string '1992' is nowhere in the description
end
Back to top
string.startswith(input, starts)
A check to see if a string starts with a certain string
Parameters
Parameter
Type
Description
input
String
The string to check
starts
String
The possible sub-string
Return values
Type
Description
Boolean
true if <input> starts with <starts>, otherwise false
Example(s)
diss = "You are so dumb that your dog teaches you tricks."
if string.startswith(diss, "Yo mama") then
log("You just got schooled by a yo-mama diss!")
elseif diss:startswith("You") then
log("You just got schooled with a diss on you!")
-- this is what gets logged
else
log("Some other diss was made")
end
Back to top
string.endswith(input, ends)
A check to see if a string ends with a certain string
Parameters
Parameter
Type
Description
input
String
The string to check
ends
String
The possible sub-string
Return values
Type
Description
Boolean
true if <input> ends with <ends>, otherwise false
Example(s)
diss = "You are so dumb that your dog teaches you tricks."
if string.endswith(diss, "Yo mama") then
log("You just got schooled by a yo-mama diss!")
elseif diss:endswith("You") then
log("You just got schooled with a diss on you!")
-- this is what gets logged
else
log("Some other diss was made")
end
Back to top
tblsEqual(t1, t2)
Checks (recursively) if the two given tables are the same - Order of the given tables does not matter
Parameters
Parameter
Type
Description
t1
Table
One of the two tables to check
t2
Table
The second table to check
Return values
Type
Description
Boolean
true if both tables contain the same elements, otherwise false
-- new_tongue_twister == "shmeter shmiper shmicked a shmeck of shmickled shmeppers"
incorrect = "Young man, your going to keep your room clean, or else you're grounded!"
correct = incorrect:replace("your", "you're", 1)
-- correct == "Young man, you're going to keep your room clean, or else you're grounded!"
Back to top
string.split(input, delim, autoNum)
Splits a string into a table
Parameters
Parameter
Type
Description
input
String
The item you want converted into a table
delim
String
The string that you want to divide the input by (Note: this gets excluded from the resulting table); If set to nil or an empty string is used, it will split by every character
autoNum
Boolean
true if you want the function to turn strings of numbers to the number type
Return values
Type
Description
Table
A table of strings (and possibly numbers)
Example(s)
drinks = 'tea, coffee, water, beer'
drinks_table = string.split(drinks, ", ") -- autoNum is optional
The number of places you want to round the number to
Return values
Type
Description
Number
The rounded number
Example(s)
pi = round(math.pi, 2)
-- pi == 3.14
e = round(2.71828, 0)
-- e == 3
Back to top
copyFile(srcFilePath, dstFilePath, overwrite)
Copies a file from one location to another
Parameters
Parameter
Type
Description
srcFilePath
String
The original path for the file that you want to copy
dstFilePath
String
The path + file name of where you want the file to be copied to
overwrite
Boolean
true if you want it to automatically overwrite a file if one exists at the destination, false if you want it to cancel if there's an existing file at the destination
-- copies the "script1.lua" file to the AutoTouch scripts directory
-- since was not given, it is set to false by default
Back to top
fileExists(file)
Checks if a certain file or folder exists
Parameters
Parameter
Type
Description
file
String
The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.
Return values
Type
Description
Boolean
true if the file/folder does exist, otherwise false
Example(s)
if fileExists("/var/mobile/Library/AutoTouch/Library/log.log") then
log("The log exists!") -- which it does, so this gets printed to the log
end
if fileExists("/var/mobile/fakeFolder") then
log("This should not get logged....")
else
log("Fake folder is fake!") -- this is what gets printed to the log
end
Back to top
formatLog(option, value)
Formats the log for easier viewing Note: You only have to run this once. After that, anything added to the log will be in the
specified format. If you want it to go back to the default settings, run the function with no parameters (this will apply to anything logged after reverting it)
Parameters
Parameter
Type
Description
option
String
Can either be 'prefix' (or 'p') to customize the prefix of the line, 'seperator' ('sep' and 's' also work) to customize the seperation between each entry
value
String
What you want to be used for the specified option
Return values
Type
Description
None
None
Example(s)
-- log.log
--[[
02-11 12:18:44 Testing 1, 2, 3 ....
02-11 12:19:00 Did this pause for 16 seconds?
02-11 14:56:36 Script ran successfully!
--]]
editLog('p', '>')
editLog('s', '*')
-- log.log
--[[
> Testing 1, 2, 3 ....
* * * * * * * * * * * * * * * * * * * *
> Did this pause for 16 seconds?
* * * * * * * * * * * * * * * * * * * *
> Script ran successfully!
--]]
Back to top
getDir(dir)
Gets all the folders/files in specific directory
Parameters
Parameter
Type
Description
dir
String
Path of the directory you want to get the files in
Return values
Type
Description
Table
A list of the folder/file names
Example(s)
AT_Library_Files = getDir("/var/mobile/Library/AutoTouch/Library") -- the last slash is optional
print(AT_Library_Files)
-- prints "{'data.sqlite3', 'license', 'log.log'}" to the log
Back to top
getFileSize(fileName)
Gets the size of the specified file
Parameters
Parameter
Type
Description
file
String
The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.
Return values
Type
Description
Number
The number of bytes the file is
Example(s)
oneKB = getFileSize("oneKilobyteFile.lua")
-- oneKB == 1024
Back to top
getLine(file, lineNum)
Similar to getLines, but just gets one specified line
Parameters
Parameter
Type
Description
file
String
The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.
lineNum
Number
The line that the desired text is on (starts at 1)
Return values
Type
Description
String
The specified line
Example(s)
-- mySecrets.txt (located in /var/mobile/Documents/)
-- prints "{'I have 6 toes', 'Crosswords make me horny', 'I ate dog food once out of curiosity'}" to the log
Back to top
replaceInFile(file, before, after, limit, backup)
Replaces some text within a specified file
Parameters
Parameter
Type
Description
file
String
The path/location of the target file; note that if the file is in the scripts directory, you can input just the name of the file.
before
String
The text in the file that you want replaced
after
String
The new text that you want to replace the old text with; set to nil or an empty string if you want to simply remove the text.
limit
int
Sets the number of replacements you want to be made in the file; set to nil or 0 to change every found location.
backup
Boolean
Whether or not you want the file to be backed up. If set to true, it will create a copy with a ".bak" extension; if left out or set to nil, it will default to true.
-- makes a folder called "YoutubeVideos" in the "/var/mobile/Downloads" folder
Back to top
help(func)
Print to the log more information about a topic
Parameters
Parameter
Type
Description
func
String
If left empty, it will provide general information; If "functions" is used, it will log a list of the function names; If a string of a function name is used, it will log a plain text version of the help shown in this document.
Return values
Type
Description
None
None
Example(s)
help() -- logs contact info and other general-info kind of stuff
help("functions") -- logs a list of functions
help("str") -- logs help about the function 'str'
Back to top
pause(time, unit)
An easier way to use usleep without having to wonder if you've used enough 0s
Parameters
Parameter
Type
Description
time
Number
The number of s that you want to sleep for
unit
String
If left empty or nil, it will sleep for
Return values
Type
Description
None
None
Example(s)
pause(1000000) -- pauses for 1 million microseconds, aka a second
pause(1, "s") -- also pauses for 1 second
Back to top
print(...)
Implements Lua's print function while also adding in support for tables
Parameters
Parameter
Type
Description
...
0 or more objects of any type
The stuff you want to be printed
Return values
Type
Description
None
None
Example(s)
print("The following", 3, "objects were found on the deceased's body:",{"keys", "a used straw", "cucumber"})
Back to top
pprint(tabl)
Pretty prints a table to the log using indents and formatting
Converts a color in RGB format to its hexadecimal value
Parameters
Parameter
Type
Description
r, g, b
Numbers
The red, green, and blue values for the color; Note that I comressed these values into one row for simplicity. When calling the function, these values are separated
Return values
Type
Description
String
The hexadecimal equivalent
Example(s)
{None currently given}
Back to top
rgbToName(r, g, b, colorScheme)
Converts a color in red, green, blue format to the closest matching name
The closest matching color name based on the input
Example(s)
{None currently given}
Back to top
xToName Color Scheme Options
For the xToName functions, the second parameter allows for a "colorScheme". Of the 4 choices for schemes, pick the one which suits your needs the best.
Below, I list a description of all 4 and your options for the "colorScheme" parameter.
Note that, for each of the color schemes, each level builds upon the previous; in addition, colors #1 takes 3 from grayscale, #2 takes 9 from grayscale, and #3 takes the remaining 7 from grayscale.
Grayscale - This scheme includes black and white, along with 19 shades of gray in between. Available options to use this scheme are:
0
"gray"
"grey"
Colors #1 - This scheme has 20 colors total (3 from previous + 17 new). Available options to use this scheme are:
1
"small"
"basic"
Colors #2 - This scheme has 59 colors total (20 from previous + 39 new). Available options to use this scheme are:
2
"medium"
"indepth"
Colors #3 - This scheme has 89 colors total (59 from previous + 30 new). Available options to use this scheme are: