Introduction
Welcome back to the birds nest 🪶 .
Today we’ll be creating 2 Shell scripts to keep our work computer active while we’re busy working on getting our WiFi money so you can focus on building that 2nd income stream.
With more and more companies becoming fully remote by the day, there’s been an influx of surveillance software that monitor your activity status on popular messaging tools like Microsoft Teams, Skype, and Slack. I’ve seen software that send’s weekly PDF’s to managers regarding their employees time away from the computer. I’ve heard countless stories of people being questioned about their activity status- some even being fired for not being truthful. I believe firms are quickly adapting this software with the increase in work from home opportunities.
Let’s get to it 🦅
MacOS users (Windows users scroll below)
We’ll be using osascript. It’s a command to run a script from the shell. The shell is also known as a terminal. This command lets us access built in tooling on our computer.
A script is a set of instructions that we’re going to be telling the computer to follow. Alright enough of the basics.
So how do we keep our computer awake? We can do this by having our computer press a key (in this case, ‘.’) every minute. This will allow the computer screen to stay awake until you decide to stop the script.
Here’s the script:
osascript -e 'tell application "System Events"
repeat
key code 65
delay 60
end repeat
end tell'
To execute the script copy and paste this into a text document and save the file as a .sh file. I named mine sleeper.sh .
Then run sh sleeper.sh
in the terminal. Example below:
$ sh nameOfFile.sh
Here’s how the script works:
osascript -e 'tell application "System Events"
This line above uses the osascript. “-e” is a flag used when writing a command. this command in this case is ‘tell application’. This invokes the System Events which is an operation specific to MacOS.
repeat
key code 65
delay 60
end repeat
This code above is an example of a loop. A loop is a sequence of instructions that is continually repeated until a certain condition is met. In this case we are repeating the command key code 65
every 60 seconds. Key code 65 is the code for “press the ‘.’“ The delay keyword is a built in command which delays the key code 65 command every 60 seconds. Change the delay for yourself and see what best fits your needs. Finally we quit the loop when we quit the script.
To quit the script you can close the terminal window or hit the key Command + c.
Windows users
Get a Macbook….
Okay just kidding- only a little. Here’s the script for the windows operating system. Open a new text document paste this code and save it as a filename ending in .ps1 .
Here’s the script:
param($minutes = 60)
$myshell = New-Object -com "Wscript.Shell"
for ($i = 0; $i -lt $minutes; $i++) {
Start-Sleep -Seconds 60
$myshell.sendkeys(".")
}
To run it open up PowerShell (note: this works for windows 7 and above) and go to the directory in which you saved the file and type: (ignore the $ sign)
$ .\nameOfFile.ps1 120
Finally, open up a text document and see look at your script go to work :)
In this case the 120 is the # of minutes you’d want this script to run.
Here’s how it works. It’s very similar to our loop explanation above. However we are accepting a parameter when we run our script. In this case 120. Feel free to change this to any number. Note, this is how long you want the script to run in minutes. The parameter 120 is then sent into our script and prints “.” (period) every one minute.
Try these scripts out and keep your computer active while you’re away from your computer. As always, become a paid sub and we’ll go way more in-depth to customizing this script to our needs. Now run this script and start building that 2nd income stream :)
Sharing this with my sister. She works remotely due to COVID, and is able to get most of her work done in less than half it used to take her. She wasn't repremanded, but when her superiors asked her why she wasn't spending 9-5 on her work issued laptop, she was honest with them. Since it's a work issued Mac, I am wondering if the IT people at her company will pick up on this? For the sake of her anonymity, I won't say the name of the company, but it's a very reconiazable software company.