How To Create, Edit And Execute Scripts


Introduction

If you are still a beginner in the Android customization field, sometimes when you browse through the internet, you might come across typed texts called scripts and you may be wondering what they mean. What seems amazing the most is that these scripts do not usually contain normal texts or understandable sentences as there might be a ton of unusual characters and punctuations.

Script files let you automate tasks and in this article, we are going to see what scripts are and how to create, edit and execute them. Just ride along.

What Are Script Files?

A Script file is a programmed file which contains one or multiple commands/codes (typed texts) that run in sequence to perform various actions with a command-line that you would have done manually. These typed texts makes up a script. You can type commands and execute them through command-line programs but with script files, the work is being simplified and saves your time and avoids mistakes too because the files have already been typed and saved to be executed anytime and as many times as possible. The texts have already been typed (correctly) for you to just execute. If you don’t know much about scripting or you don’t know about the right commands to use to get a particular task done, you can use prepared script files.

A Script

Types Of Script Files

Every operating system has their own types of scripts that they support and the format used in writing a script is known as the scripting language of that particular script.

— Script files in Windows are called batch files (batch scripts) and they have the extension .bat. The extension can also be .cmd or .btm. Unix, Linux, Ubuntu, Android and MacOS use shell or bash scripts (extension is .sh).

Types Of Shells

— A shell is a command-line interface to run commands and scripts. It can sometimes be referred to as a console, terminal, command interpreter, etc. Below are different types of shells

Types Of Shells In Windows

• Command Prompt (CMD).

• PowerShell. PowerShell is more advanced than CMD.

Types Of Unix Shells

— There are basically two types of Unix shells. Unix shells are the shells in a Unix or Unix-like system such as MacOS, Ubuntu, Linux, Debian, Android, etc.

1. Bourne Shell commonly called Shell (sh). The prompt for this shell is $. This is the default shell in Unix (but any of the below shells can be used). All the other shells below are derivatives of the Bourne Shell.

• Bourne Again Shell, also called GNU Bash (bash)- The most popular shell nowadays. Default shell on Ubuntu, Linux, MacOS (MacOS has now switched to zsh) and also occur in Unix. It is an improvement of the Bourne Shell (sh). Windows can be configured to run bash commands.

• POSIX Shell (sh).

• Korn Shell (ksh).

• Z Shell (zsh) – MacOS.

• Fish Shell.

2. C Shell. The prompt for this shell is %. Its subcategories are:

• C Shell (csh).

• TENEX or TOPS C Shell (tcsh).

— To see all the shells available on a Unix system, run the command, cat /etc/shells.

— To check the default or current shell (and its location) on Unix systems, run echo $SHELL. You might get something like /system/bin/sh, /bin/sh, /system/bin/bash or /bin/bash, etc. Third-party applications can come with their own shells (in their own directories) e.g the Android terminal emulator Termux gave /data/data/com.termux/files/usr/bin/bash – those that don’t will use the default shell.

bash vs sh

Bash and sh are two different shells in Unix systems. Bash is an improvement and simplified version of sh. Bash scripting is scripting specifically for bash while shell scripting is scripting in any shell (not just sh). The bash interpreter is usually installed as /bin/bash or /system/bin/bash – therefore, bash commands start with #!/bin/bash or #!/system/bin/bash. The sh interpreter is usually installed as /bin/sh or /system/bin/sh – therefore, sh commands start with #!/bin/sh or #!/system/bin/sh. Because bash is a modification of sh, it is compatible with sh.

How To Create Script Files

You need a notepad, code editor or text editor and you should have some basic knowledge about typing commands in a command-line tool. See How To Use Command-line Tools: Android Terminals, CMD, PowerShell, etc.

i) Creating A Basic Batch File (For Windows)

Let us create a script file that will display I have a knowledge about creating batch files! on the terminal when executed.

— On your computer, search Notepad and click on it (you can use any other code or text editor) – please don’t include the numbers, they are just to make the different lines clearly visible (like a code editor will do).

@ECHO OFF
ECHO I have a knowledge about creating batch files!
PAUSE

@ECHO OFF – makes only the message shows on the terminal, disabling the display prompt. Without it, the path to the script file and every command will be displayed before the expected results. Hence, the command helps to print a clean result. It is usually placed at the start of the script or at the start of a command that you want to be displayed cleanly. Note that it applies to all commands below @ECHO OFF but doesn’t apply to commands above @ECHO OFF.

ECHO – the terminal shows the text after the space. You can add multiple ECHO commands on new lines. This command is equivalent to echo on Unix shells. The ECHO commands are in the form:

ECHO <text>

PAUSE – Allows the console to stay open after running the command, otherwise, it closes. It usually sits at the end of the script. You can also use it in between commands when running multiple commands and want to pause between each. To run the next command after one completes, you will be told to press any key, just do it. Note that it doesn’t apply to commands above PAUSE.

— Now is time to save our script. Click the File menu at the top.

— Select Save or Save as.

— Input a name of your choose. The extension should be in .bat. e.g MyScript.bat (the extension can also be .cmd or .btm) – be careful not to save it as MyScript.bat.txt as some beginners might mistakenly do. If the filename is made up of two or more words, join them e.g MyScript.bat instead of My Script.bat.

— You can then execute the script file as explained below.

ii) Creating An Advanced Windows 10 Batch File

Let us create a script file that will display the details of your PC and then launch a webpage (on your default browser).

— On your computer, search Notepad and click on it (you can use any other code or text editor) – please don’t include the numbers, they are just to make the different lines clearly visible (like a code editor will do).

— Copy and paste the following texts:

@ECHO OFF 
:: This batch file details Windows 10, hardware, and networking configuration.
TITLE My System Info
ECHO Please wait... Checking system information.
:: Section 1: Windows 10 information
ECHO ============================
ECHO WINDOWS INFO
ECHO ============================
systeminfo | findstr /c:"OS Name"
systeminfo | findstr /c:"OS Version"
systeminfo | findstr /c:"System Type"
:: Section 2: Hardware information.
ECHO ============================
ECHO HARDWARE INFO
ECHO ============================
systeminfo | findstr /c:"Total Physical Memory"
wmic cpu get name
wmic diskdrive get name,model,size
wmic path win32_videocontroller get name
wmic path win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution
:: Section 3: Networking information.
ECHO ============================
ECHO NETWORK INFO
ECHO ============================
ipconfig | findstr IPv4
ipconfig | findstr IPv6
START https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715
PAUSE

The @ECHO OFF, ECHO and PAUSE commands have been explained above

TITLE – replaces the default title in the title bar of the console. The TITLE commands are in the form:

TITLE <text>

:: – Allows writing comments and documentation information. Its details are not shown in the console. These commands are in the form:

:: <text>

START – Used to open a webpage (with the default browser) or launch an applications like CMD, PowerShell. These commands are in the forms:

START <web-address>

In our case, the START command will open the web browser in the official support page outlining the Windows 10 system requirements, which you can check against your information. The web address is https://support.microsoft.com/en-us/windows/windows-10-system-requirements-6d4e9a79-66bf-7950-467c-795cf0386715.

If it is an installed app you want to launch, use:

START <installed-application-path>/<filename>.exe

Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc. For example, launching Notepad should be:

START C:\Windows\System32/notepad.exe

For popular apps like CMD, PowerShell, you can just use their names instead of specifying their paths. The command here is:

START <application>

Examples: launching CMD and PowerShell respectively

START CMD
START PowerShell

The normal commands (systeminfo | findstr /c:”OS Name”, wmic cpu get name, ipconfig | findstr IPv4, etc) – These are dedicated commands that the system understands, the same as how all operating systems have their own commands – for example think about shell commands in Android (mkdir /sdcard/Pics, cd /data/local, su, etc). They occur without the starters like TITLE, START, ::. You can add multiple commands on separate lines. You have to learn these commands because they are the ones responsible for carrying out all the tasks – you can search for the various Windows commands online. These commands are in the form (let’s assume there are three of them):

command 1
command 2
command 3

Sections – The output will be differentiated into three sections (WINDOWS INFO, HARDWARE INFO, and NETWORK INFO) indicated by the portions of the script with the below format:

ECHO ============================
ECHO <TEXT>
ECHO ============================

Example

ECHO ============================
ECHO WINDOWS INFO
ECHO ============================

The output should read:

============================
WINDOWS INFO
============================

— Now is time to save our script. Click the File menu at the top.

— Select Save or Save as.

— Input a name of your choose. The extension should be in .bat. e.g MyScript.bat (the extension can also be .cmd or .btm) – be careful not to save it as MyScript.bat.txt as some beginners might mistakenly do. If the filename is made up of two or more words, join them e.g MyScript.bat instead of My Script.bat.

— You can then execute the script file as explained below.

iii) Creating A Batch File For ADB/Fastboot On PC

Adb and fastboot commands are commands that are executed from a computer and they will take effect on a connected Android device. For more details, see SDK Manager And The SDK Platform Tools | ADB And Fastboot Commands | Android Studio.

We will be creating a script file to execute adb and fastboot commands from our computer.

— On your computer, search Notepad and click on it (you can use any other code or text editor) – please don’t include the numbers, they are just to make the different lines clearly visible (like a code editor will do).

— Type an adb, adb shell or fastboot command e.g the command to see if there’s a device connected in adb mode:

adb get-state

— To run multiple commands, list them in separate lines e.g the command to see if there’s a device connected in adb mode and the command to list connected devices. Add PAUSE at the end to prevent the console from closing after executing the commands:

adb get-state
adb devices
PAUSE

— You can save the file or continue below for more options

— To include a PAUSE in a line between two commands to pause after running the first. You will be told to press any key to continue after one command completes, just do it:

adb get-state
PAUSE
adb devices
PAUSE

— Since && is used to run multiple commands, you can use it with all the adb commands in a single line unlike listing them in separate lines e.g:

adb get-state && adb devices
PAUSE

— To get a Done! text after running the commands. @ECHO OFF will display a clean output for commands below it:

adb get-state
PAUSE
adb devices
@ECHO OFF
ECHO Done!
PAUSE

— To get a clean output overall where only the necessary outputs of the commands are shown, use the @ECHO OFF command at the start of the script:

@ECHO OFF
adb get-state
adb devices
ECHO Done!
PAUSE

— Include a title called My Device (it will be displayed at the tittle bar of the console, overriding the default one):

@ECHO OFF
TITLE Check Device
adb get-state
adb devices
ECHO Done!
PAUSE

— Select Save or Save as.

— Input a name of your choose. The extension should be in .bat. e.g MyScript.bat (the extension can also be .cmd or .btm) – be careful not to save it as MyScript.bat.txt as some beginners might mistakenly do. If the filename is made up of two or more words, join them e.g MyScript.bat instead of My Script.bat.

— You can now run the command as explained below.

Flashing Android
— You can use the approach above to create a script file to flash the firmware (or certain partitions) of your Android device. Let’s say we have the boot, recovery, system, vendor, vbmeta partitions to flash. The script should be:

* A-only, non-dynamic devices:
@ECHO OFF
adb reboot bootloader
fastboot -w
fastboot flash system system.img
fastboot flash boot boot.img
fastboot flash recovery recovery.img
fastboot flash vendor vendor.img
fastboot flash vbmeta vbmeta.img
fastboot reboot
PAUSE


* A-only, dynamic devices:
@ECHO OFF
adb reboot bootloader
fastboot -w
fastboot flash boot boot.img
fastboot flash recovery recovery.img
fastboot flash vbmeta vbmeta.img
fastboot reboot fastboot
fastboot flash system system.img
fastboot flash vendor vendor.img
fastboot reboot
PAUSE


* A/B, non-dynamic devices:
@ECHO OFF
adb reboot bootloader
fastboot -w
fastboot flash boot_a boot.img
fastboot flash boot_b boot.img
fastboot flash vbmeta_a vbmeta.img
fastboot flash vbmeta_b vbmeta.img

fastboot flash system_a sytem.img
fastboot flash system_b sytem.img
fastboot flash vendor_a vendor.img
fastboot flash vendor_b vendor.img
fastboot reboot
PAUSE


* A/B, dynamic devices
@ECHO OFF
adb reboot bootloader
fastboot -w
fastboot flash boot_a boot.img
fastboot flash boot_b boot.img
fastboot flash vbmeta_a vbmeta.img
fastboot flash vbmeta_b vbmeta.img
fastboot reboot fastboot
fastboot flash system_a sytem.img
fastboot flash system_b sytem.img
fastboot flash vendor_a vendor.img
fastboot flash vendor_b vendor.img
fastboot reboot
PAUSE


— Note:
• A-only devices have a recovery partition.
• A/B devices lack a recovery partition (the reason there is no flash recovery command). They have double slots, hence partitions exist in twos: partition_a and partition_b.
• Non dynamic devices don’t have dynamic partitions, so you use the bootloader to flash all partitions.
• Dynamic devices have dynamic partitions. You use the bootloader to flash the normal partitions, then fastbootd to flash dynamic partitions (system and vendor). fastboot reboot fastboot reboots from bootloader to fastbootd (the fastboot tools version should be equal to or greater than 29 when you run fastboot --version.
Fastboot -w will reset the device, wiping everything. If you don’t want to wipe your data, then eliminate the command.
— Other Useful Commands:

fastboot erase system (wipes the OS)
fastboot erase cache (wipes the cache partition)
fastboot erase userdata (wipes the data partition and internal storage).

— You can flash the entire firmware of your device this way. To run the script, move the file to the platform tools folder with all the partitions to be flashed as stated in the script. Using File Explorer, go to the platform tools folder and double-click the script file. Or using CMD, run cd <path-to-platform-tools-folder> then <script-filename>.bat. Your phone should be ON before running this script. If it is already in bootloader mode, then remove the adb reboot bootloader command from the script.

iv) Creating A Basic Bash File (For Android)

We will be creating a shell script to reboot our device.

— Open a text or code editor on your phone to start typing.

— Type the following lines:

#!/system/bin/sh
reboot
$chmod +x <filename>.sh

— Replace <filename> in $chmod +x <filename>.sh with the name you intend to save the file. e.g if I would save the file as reboot (extension not included because it is always .sh), then the line should be $chmod +x reboot.sh and the script should now read:

#!/system/bin/sh
reboot
$chmod +x reboot.sh

#!/system/bin/sh – tells the interpreter that this is a shell script and the scripting program is located in /system/bin. It can take similar forms like #!/bin/sh, #!/bin/bash, #!/system/bin/bash, etc depending on the scripting program’s name and path, If you have a rooted device, you can open such directories to see which is present and its name then use in the command. Whether it’s su or bash, the command will be executed. Also, the scripting program will usually be located in both /system/bin and /bin, so you can use any of the paths in the command.

reboot – the command to be executed. You can add multiple commands on separate lines.

$chmod +x <filename>.sh – makes the command executable.

— Select Save or Save as

— Input a name of your choose (it should be the <filename> in $chmod +x <filename>.sh above – i.e reboot in my case). The extension should be in .sh e.g reboot.sh. If the filename is made up of two or more words, join them e.g MyScript.sh instead of My Script.sh.

— You can now run the command as explained below.

— NB: Another way is to create an empty file whose extension is .sh using a file manager and then open it in a code or text editor, type the commands and save it.

v) Already-Typed Scripts

— Sometimes when you browse through the internet, you will find scripts that have already been written for a particular task. To create a script file from it, copy and paste the texts in a text or code editor, then save it with the name of your choose. The issue here is getting the right code editor that will maintain the texts exactly as they should be. Using my Android device, I tested a few code editors from Play Store but didn’t get good results. The only code editor that did the job well was the built-in code editor of MiXplorer Silver file manager (the best Android file manager out there). Here is how to use MiXplorer Silver’s code editor.

— Install MiXplorer Silver file manager and launch it.

— Click on the add (+) button at the bottom, choose File from the options.

— Choose the name you want to give the file. Now the extension should be that supported by the OS the script is meant to be run on e.g .bat (or .cmd) for Windows, .sh for Android, Linux, Ubuntu, etc. Save the file.

— Tap on it then choose Code Editor (not Text Editor). Copy and paste the script.

— Now tap the Save button at the top and you are done.

— You can then transfer the file to your computer and use it (if it is meant for the computer) or use it on your phone (if it is meant for the phone).

Editing Script Files

Script files are very easy to edit than create.

— If you want to edit a batch file in Windows, locate the file, right-click on it and choose Edit. It will open in Notepad. After making the changes, choose File > Save (not Save as). Follow a similar procedure if you use another text or code editor. Most text and code editors even have the option to choose files to edit.

— Windows doesn’t support bash files. To edit a bash file, you can install a third party text editor that supports it like Notepad++, Hex Editor, etc. But if you insist on editing a bash file on Windows without using a third party tool, first change the script file’s extension to .txt. You can then open it in Notepad. After doing the necessary changes, save the file and change the extension back to .sh.

— If you want to edit a script file in Android, install a text or code editor (some file managers like MiXplorer Silver, etc have built-in text and code editors) and do the editing. For a file manager, you need to long-press the file, choose Open with, [choose open as Text if available] then choose either a text or code editor (depending on what will appear). Don’t forget to choose Save instead of Save as when saving an edited script file.

Running Script Files On Android

You can run .sh script files through a terminal on Android. You can use a terminal emulator (e.g Termux), a custom recovery’s terminal or supported file managers (MiXplorer Silver or Script Manager – SManager, etc). Your device needs to be rooted and then grant root to the program you want to use.

– SManager

Method 1: This method does not require us to switch to the script’s path before running it.

— Launch SManager, grant access to files. In the next pop up, choose BROWSE AS ROOT and click OK. Choose the three vertical dots at the top-right. Choose Console. Choose shell to open the terminal. Alternatively, while you are in the Home screen, just swipe left to open the shell.

— Type su and press enter to grant root. To run the script file, use the below command:

<Path-to-file>/<filename>.sh

— Replace <path-to-file> with the actual path to the script file and replace <filename> with the actual name of the file.

Example: a script named unpackimg (unpackimg.sh with extension) is found in system root > data > local > AIK-mobile. To execute it, the commands should be:

su
/data/local/AIK-mobile/unpackimg.sh

— If this method fails, then use the next

Method 2: This method requires us to switch to the script’s path before running it.

— Launch SManager, grant access to files. In the next pop up, choose BROWSE AS ROOT and click OK. Choose the three vertical dots at the top-right. Choose Console. Choose shell to open the terminal. Alternatively, while you are in the Home screen, just swipe left to open the shell.

— Type su and press enter to grant root. To run the script file, use the below commands one after another:

cd <path-to-file>
sh <filename>.sh

— Replace <path-to-file> with the actual path to the script file and replace <filename> with the actual name of the file.

Example: a script named unpackimg (unpackimg.sh with extension) is found in system root > data > local > AIK-mobile. To execute it, the commands should be:

su
cd /data/local/AIK-mobile
sh unpackimg.sh

Method 3: This method does not require us to type commands

— Locate the script file and tap on it. Choose Is script and then tap on RUN at the top-right.

– MiXplorer Silver

Method 1: This method requires us to switch to the script’s path before running it.

— Launch MiXplorer Silver file manager. Grant storage access and root. Tap on the three vertical dots at the top-right and choose Execute.

— Run the commands (you can type and run all the commands at once by starting a new line for a new command):

su
cd <path-to-script>
sh <filename>.sh

— Replace <path-to-file> with the actual path to the script file and replace <filename> with the actual name of the file.

— Click on Execute.

Method 2: This method requires us to manually navigate to the script’s path before opening a terminat to run it.

— Go to the folder where the script file is found. Tap on the three vertical dots at the top-right and choose Execute. Run the below commands (you can type and run all the commands at once by starting a new line for a new command):

su
sh <filename>.sh

— Replace <filename> with the actual name of the file.

– Terminal Emulator e.g Termux

— This method requires us to switch to the script’s path before running it.

— Launch Termux. Run su and grant root.

— Type and run the below commands one after another:

su
cd <path-to-file>
sh <filename>.sh

— Replace <path-to-file> with the actual path to the script file and replace <filename> with the actual name of the file.

Running Script Files On Windows

You can run .bat, .cmd or .btm script files on Windows through File Explorer, CMD or PowerShell.

– File Explorer

This method does not require a terminal

— Launch File Explorer and navigate to the file.

— Double-click on the script file to run it. After running the script, the console will automatically close unless there’s a PAUSE command in it.

— If a command in the batch file requires administrator privileges, you will have to run the script as an admin by right-clicking the file and selecting the Run as administrator option.

— [If it is an installed app you want to launch, you should follow the same procedure. Installed Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc].

– CMD or PowerShell

Method 1: This method requires us to manually navigate to the script’s path before opening a terminal to run it.

— Launch File Explorer and navigate to the file.

— Open either CMD or PowerShell in that folder. To open CMD, highlight the text in the address bar and replace with cmd, then press Enter. To open PowerShell, hold down the Shift key (on the keyboard) and click on an empty area (inside the folder) then choose Open PowerShell window here from the options.

— Run the script file using the below command:

<filename>.bat

— Replace <filename> with the actual name of the file.

— After running the command, the console won’t close even if there’s no PAUSE command because the script was run from an already opened terminal.

— [If it is an installed app you want to launch, you should follow the same procedure. Installed Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc. Here the command should be <filename>.exe]

Method 2: This method requires us to switch to the script’s path before running it.

— Launch either CMD or PowerShell. To launch CMD, search Command Prompt (using Windows Search on the Taskbar). To open PowerShell, hold down the Shift key (on the keyboard) and click on an empty area anywhere then choose Open PowerShell window here from the options.

— Run the below commands one after another:

cd <path-to-script>
<filename>.bat

— Replace <path-to-file> with the actual path to the script file and replace <filename> with the actual name of the file.

— [If it is an installed app you want to launch, you should follow the same procedure. Installed Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc. Here the commands should be cd <path-to-app>.exe and <filename>.exe].

Running Bash Script Files On Windows 10 And Above

Below are the steps to set up and run bash files and commands on Windows.

Method 1: Enabling Windows Subsystem for Linux (WSL)

By default, Windows does not execute bash or shell files [ending in .sh]. But there’s a built-in feature called Windows Subsystem for Linux (WSL) that when enabled, one can execute them easily. Therefore, you won’t be needing Ubuntu or any other Linux distro installed unless your scripts need the support of the real Linux kernel.

— Go to Settings > Update & Security > For developers. Turn on Developer Mode and choose Yes from the pop up. Using the search bar on the Settings page or Windows Search (on the Taskbar), search for Windows Features, then choose Turn Windows features on or off.

— Scroll to find Windows Subsystem for Linux, check the box, and click OK. Windows will start searching for the required files.

— Once done, choose Restart now to finalize the changes. You can choose to restart later using Don’t restart.

— Now you need to install a Linux terminal environment. Download Ubuntu by Canonical Group Limited from Microsoft Store here. The program needs the following requirements

OSWindows 10 version 16215.0 or higher
Architecturearm64, x64
KeyboardIntegrated Keyboard
Memory4GB (minimum), 8GB (recommended)

— To launch, use ubuntu on the command-line prompt or Windows Terminal (CMD or PowerShell), or click on the Ubuntu tile in the Start Menu.

— Th required resources will start installing upon first launch.

— When that is done, you will need to create a default UNIX user account. The username does not need to match your Windows username. It should start with a lowercase letter e.g sako in my case.

— Now input a password. In order not to easily forget, you can use the Windows password. The password might not be visible while typing so you have to be careful. After you set the password, you need to retype it the second time to confirm. If the both don’t match, you will have to repeat the process by typing y. After doing things correctly, the installation will be completed.

— Henceforth, you can run bash scripts, Linux command-line tools like sed, awk, grep and you can even try Linux-first tools like Ruby, Git, Python, etc directly on Windows. One can also access Windows filesystem from within bash. Remember, this is a developer toolset to help you write and build all your code for all your scenarios and platforms. This is not a server platform upon which you will host websites, run server infrastructure, etc.

Method 2: Installing Ubuntu or any other Linux distro

— You should have a Ubuntu or any other Linux distro installed. Let’s consider the case of Ubuntu here.

— Ubuntu will mount or make all your Windows directories available under /mnt. e.g the C drive is available at /mnt/c, the desktop will be available at /mnt/c/users/<username>/desktop, etc.

— To execute a bash script, use the below commands:

cd <path-to-script-file>
sh <filename>.sh

Scheduling Script Execution

You can set up and schedule to run script files on both Android and Windows. While there’s a built-in program to perform this task on Windows, you will need a third party program on Android.

1. Windows

There are two ways that you can schedule the execution of a script file on Windows:

Method 1: Run batch files on startup (Win 10+)

Windows 10 [and above] has a folder called Startup, which the system checks every time it starts to run applications, shortcuts, and scripts automatically. Taking advantage of this, you can run a script file each time you log into your account. To do the configuration, follow the steps below:

— Open File Explorer and locate the script file. Right-click on it and choose Copy.

— Press Win + R keys on the keyboard to bring up the Run dialog. Type shell:startup and click OK.

— Right-click on an empty space in the folder and choose Paste. Close File Explorer.

— You are done. Each time you log into your account, the script file will be executed automatically. [If it is an installed app you want to launch on startup, you should follow the same procedure. Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc].

Method 2: Run batch file with Task Scheduler (Win 7,8, 10+)

Task Scheduler allows you run a script file at a specified time. To do the configuration, follow the steps below:

— Search for Task Scheduler and launch it.

— Click on Task Scheduler Library. Now right-click on it and select New Folder. Give a name of your choice e.g SakoScripts. Note that we could have just added the task but we choose to put it in our own folder so that we don’t mix it with those of the system.

— Double-click Task Scheduler Library to expand it. Click on SakoScripts. Now right-click on SakoScripts and select Create Basic Task.

— Type a Name for the task and [optional] a Description then click Next. In the next box, choose an option that is convenient to you. In my case, I will choose to run the command Weekly. Now click on Next

— Use the Start section to choose a starting date and time

— Use the Recur every section to choose if the task should be run each week, after every two weeks, etc.

— Then choose a Day and click Next

— On the next screen, choose Start a program [you can also use the Send an e-mail or Display a message options, but these are deprecated features, which means that they may or may not work because Microsoft is no longer maintaining them]. Click Next.

— Click Browse next to the Program/script box, navigate to the file and choose it or you can use <path-to-file>/<filename>.bat [If it is an installed app you want to launch on schedule, you should follow the same procedure. Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc. Here the app’s path can be listed as <path-to-file>/<filename>.exe. But if it’s a known application like PowerShell or Command Prompt, you only need to specify the file name e.g powershell.exe]. Click Next.

Send an e-mail: Triggers an email notification with a custom message on schedule, but it requires to specify an email server to work.



Display a message: Allows to display a text message on the screen on schedule.

— Click Finish

— Once you complete the steps, the Task Scheduler will run the script during the configured time and date.

— You can run, edit, end, disable/enable, delete this task. You can also export and store it to a save place as a backup such that you can import it back to Task Scheduler any time. From its Properties section, you can also choose to run the task whether you are logged in or not or with highest privileges. You can also change the User or Group to run the task from this section.

Creating An Advanced Task
The above instructions are meant to schedule only a basic task (using the basic settings). To create a more customizable task with the Task Scheduler, you have to use the advanced settings. Note the following points if you want to create an advanced task.

You have to select Create Task instead of Create Basic Task.
— The General tab: You can configure which administrator account can run the task from the Change User or Group setting under the Security options. [Options] If you’re running a Command Prompt or PowerShell command, you can select the Run whether user is logged on or not option to prevent the command window from showing up when the task runs automatically, as it’s likely that using the Hidden option won’t work. You can choose to run only when you are logged on. If the task requires elevated privileges, check the Run with highest privileges option. The Configure for settings should be left alone unless you’re required to use a different compatibility option.
— The Triggers tab : Click the New button. Use the Begin the task drop-down menu to select one of the many triggers, including On a schedule, At startup, “On workstation unlock, and many others. For this guide, select the On a schedule option. Under Settings, you can do the configuration as you like. (Optional) In the “Advanced settings” section, you can select options to delay, repeat, stop, and expire a task. The Enabled option is checked by default. (Usually, you don’t want to change these settings unless necessary.)
— The Action tab: Click the New button. [Options] choose Start a program (you can also use the Send an e-mail or Display a message options, but these are deprecated features, which means that they may or may not work because Microsoft is no longer maintaining them). Under the Settings section, in the Program/script field, specify the script’s or [installed] application’s path by pasting or choosing the Browse button [installed Windows apps are located in C:\Windows e.g explorer.exe, regedit.exe, notepad.exe, write.exe (this is WordPad), winhlp32.exe (Get Help); C:\Windows\System32 e.g notepad.exe; C:\Program Files; Program Files (x86); etc]. Also, if it’s a known application like PowerShell or Command Prompt, you only need to specify the file name e.g powershell.exe. [Optional] In the “Add arguments” field, you can specify arguments to run the task with special instructions. For example: -NoExit -ExecutionPolicy Bypass C:\PATH\TO\SCRIPT\first_script.ps1.
Using the “powershell.exe” command and the above argument, it’ll run the script named “first_script.ps1.” The argument “-ExecutionPolicy Bypass” ensures that the script runs successfully, and the “-NoExit” argument will prevent the window from closing after running the script. (Optional) In the “Start in” field, specify the folder in which the program will start. (Usually, you can leave this setting empty.)
— The Conditions tab: The settings here are optional based on what you want. It’s a good idea to check them out.
— The Settings tab: The settings here are optional based on what you want. It’s a good idea to check them out.
— You are done. Click the OK button to create the task.

2. Android

You can also schedule the execution of a script file on Android but here, you will be needing a third-party application as there’s no such built-in feature. We will be using the SManager app – you might need a rooted device.

— Launch SManager, grant access to files. In the next pop up, choose BROWSE AS ROOT and click OK. Choose the three vertical dots at the top-right. Choose Advanced and then Scheduler

— Tap on Add a new task to open the Modify Task screen. You can then do the configuration from here. To set the time, date, days and if you want the task to be executed Daily or Monthly, tap on Repeat. To give a name to the task, tap on Name. Now tap on SELECT FILE and choose the script file (you can also use the ADD SCRIPT option to choose from your history).

— Make sure Enable is ticked (if not the task will be disabled) and tap on SAVE. You are done.

Some Common Bash Commands

basic Unix commands
Credits: TechTarget

— Other useful commands:

grepUsed to search for files.
chmodUsed to set file permission.

Conclusion

Like, Share & Comment 👍: We are done with the explanation of what a NOMEDIA file is. Hope you now know the use of a NOMEDIA file. If you find this post helpful, then scroll down to like and share. Also, drop a comment below in case of any difficulty.

Donate : Please help us to keep the site running. You can support us with whatever you have here.

Report Broken Link, Any Error, Or Wrong Information : Is a link not working, or have you found an error that needs correction, or do you believe there’s an information you have read that is wrong, report to us here. We will verify and try to update as soon as possible. Don’t forget to give us the link that is broken or to point directly to the section that needs correction. Thanks for your loyalty.

Contact 🗨: If you wish to contact the SakoPhone Team, then click here.

Join Us : Want to be part of the SakoPhone Team, join us here. Those eligible to join us are: Bloggers/Writers/Editors (to write helpful articles), Readers/Subscribers (to receive alert of every article we drop, Supporters (those who will cross-check articles and report errors, wrong details or broken links, provide helpful suggestions and information as well as increase traffic by sharing and recommending our articles to various platforms) and lastly Sponsors (those who can assist us financially with little donations to keep the site running).


Leave a comment

Create a website or blog at WordPress.com

Design a site like this with WordPress.com
Get started