Effortlessly Manage Your MacBook’s Power Settings with a Simple Bash Script

I was just looking for a way to quickly switch my power settings on my MacBook, especially when working on battery and needing to keep my computer awake for extended periods. As many MacBook users know, constantly toggling between power management modes can be a bit of a hassle, particularly if you’re someone who frequently switches from being plugged into relying solely on battery power. This is where I found a need for a more streamlined approach.

In search of a solution, I crafted a Bash script that provides a hassle-free method for switching between two power management schemes: “Normal” and “Never.” The “Normal” setting aligns with my everyday usage, allowing the computer to sleep after a certain period of inactivity, whereas the “Never” option keeps my MacBook awake indefinitely, which is perfect for those long stretches of work where you can’t afford the computer to sleep or start the screen saver.

The script utilizes the pmset command, a powerful tool in macOS for managing power settings. By running this script, you can easily toggle between these two modes with just a simple command, saving you the time and effort of manually adjusting settings in the System Preferences every time your work situation changes.

However, it’s important to note that this script requires administrative privileges to execute. This is because changing power management settings affects the entire system, so running the script with sudo is necessary to ensure it has the needed permissions.

Despite this need for elevated privileges, the script provides a straightforward and convenient way to manage your MacBook’s power settings. Whether you’re in a meeting, working on a long train journey, or just don’t want your MacBook to sleep while downloading large files, this script is an invaluable tool.

To conclude, this Bash script has been a game-changer in managing my MacBook’s power settings. It’s a simple yet effective solution for anyone looking for more flexibility in how their MacBook uses power, especially when switching between different working environments. I encourage you to try it out and see how much simpler it can make your workflow. And as always, I’m open to feedback and suggestions for further improvements!

#!/bin/bash

###########################
# Script to quickly change
# Power settings on my
# Macbook Pro
#
# James Strickland
# james@strickstuff.com 
#
###########################

echo "Power Management Options"
echo "1. Normal"
echo "2. Never"
echo "3. Quit"
echo -n "Select an option: "
read option

case $option in
    1) 
        # Normal settings
        pmset -b displaysleep 2 # Battery: Turn display off after 2 minutes
        pmset -c displaysleep 10 # Charger: Turn display off after 10 minutes
        pmset -a sleep 20 # Both: Start screen saver after 20 minutes
        ;;
    2) 
        # Never settings
        pmset -a displaysleep 0 # Never turn off display
        pmset -a sleep 0 # Never start screen saver
        ;;
    3) 
        # Quit
        exit
        ;;
    *)
        echo "Invalid option"
        ;;
esac

 

Elevate Your Flight Sim Experience

Quick Access to Real-World Airport Data with AppleScript

Welcome, flight sim enthusiasts! If you’re a fan of immersive flying experiences in games like Microsoft Flight Simulator 2020 or X-Plane, you know how crucial accurate airport information can be to enhance your virtual flights. Today, I’m thrilled to share a simple yet effective AppleScript that can elevate your flight simulation experience. This script enables you to quickly pull up detailed airport information from FlightAware just by entering an ICAO airport code. Ideal for virtual pilots who want to plan realistic routes or explore new airports in their simulator, this easy-to-use tool seamlessly integrates real-world aviation data into your flight sim setup. Join me as we dive into how you can create this handy script on your Mac, blending the lines between simulation and reality for a more enriched flying experience.

-- Start of the script
tell application "System Events"
    -- Prompt the user to enter the airport code in ICAO format
    display dialog "Enter the Airport code in ICAO format (e.g., KLAX, KJFK):" default answer "" buttons {"Cancel", "OK"} default button "OK" with icon note
    -- Store the user input in a variable
    set airportCode to text returned of result
    -- Check if the user entered a code
    if airportCode is equal to "" then
        display dialog "No airport code was entered. Please try again." buttons {"OK"} default button "OK" with icon stop
        return
    end if
end tell

-- Construct the URL using the provided airport code
set baseURL to "https://www.flightaware.com/resources/airport/"
set fullURL to baseURL & airportCode & "/IAP/all/pdf"

-- Open the URL in Google Chrome
tell application "Google Chrome"
    -- Check if Chrome is running, and start it if not
    if not (exists window 1) then reopen
    activate
    -- Open a new tab with the URL
    open location fullURL
end tell
-- End of the script

After copying the AppleScript above, open the Script Editor on your Mac, which you can find in the /Applications/Utilities folder. Paste the script into a new document. You can run the script directly from the Script Editor to test its functionality. Once you’re satisfied with how it works, you can easily convert it into a standalone application. To do this, go to the File menu in Script Editor and select ‘Save.’ In the dialog box that appears, choose a name for your application, and importantly, set the File Format to ‘Application.’ Save it to your desired location. Now, you have a fully functional app that you can launch with a click! This app will prompt you for an ICAO airport code and automatically open the corresponding FlightAware page in your browser. It’s a handy tool for flight sim enthusiasts, pilots, or anyone interested in aviation, and a great example of the practical uses of AppleScript on your Mac.

In conclusion, this simple yet powerful AppleScript is more than just a quick way to access airport codes and charts; it’s a bridge between the real world of aviation and the virtual skies of flight simulation games. By seamlessly integrating real-world airport data into your flight sim experience, you’re not only enhancing the realism of your virtual flights but also gaining valuable insights into the intricacies of airport layouts and operations. Whether you’re meticulously planning a virtual flight in Microsoft Flight Simulator 2020, exploring new destinations in X-Plane, or just curious about aviation, this tool brings a wealth of real-time information to your fingertips. It exemplifies how a small script can significantly enrich your gaming experience, making every takeoff and landing more authentic and informed.

C++ Switch Case Statement Program Page 188 number 7

/****JDS***********************
DATE      : 3/15/2022  
CREATED BY: James Strickland
CLASS     : IT-301 - Intro to Programming 
PURPOSE   : Switch Statement, employee 
            program. 

****JDS***********************/

#include 
#include 
#include 
#include 
using namespace std;

int main() {

    char department;
    double salary = 0.0;
    double raise_amount = 0.0;

    do { // start a do - while loop

        // "start" screen, menu
        cout << " +--+--+--+--+--+--+--+--+--+--+" << endl;
        cout << " |D|e|p|a|r|t|m|e|n|t|" << endl;
        cout << " +--+--+--+--+--+--+--+--+--+--+" << endl << endl;

        cout << "       Departments list" << endl;
        cout << "\t Department A" << endl;
        cout << "\t Department B" << endl;
        cout << "\t Department C" << endl;
        cout << "\t Department D" << endl;
        cout << "Please enter Deptartment A, B, C, D [Q to quit]: "; cin >> department; // get user input

        switch (department) { // begin switch statement

        case 'a': case 'A':
        case 'b': case 'B':

            cout << "Enter salary of the employee: "; cin >> salary;
            raise_amount = (salary * 0.02);
            cout << "Raise amount: ";
            cout << setprecision(2) << fixed << raise_amount << endl;
            system("pause");
            cout << "\033[2J\033[1;1H";
            break;

        case 'c': case 'C':

            cout << "Enter salary of the employee: "; cin >> salary;
            raise_amount = (salary * 0.15);
            cout << "Raise amount: ";
            cout << setprecision(2) << fixed << raise_amount << endl;
            system("pause");
            cout << "\033[2J\033[1;1H";
            break;

        case 'd': case 'D':

            cout << "Enter salary of the employee: "; cin >> salary;
            raise_amount = (salary * 0.03);
            cout << "Raise amount: ";
            cout << setprecision(2) << fixed << raise_amount << endl;
            system("pause");
            cout << "\033[2J\033[1;1H";
            break;

        default:

            cout << "Invalid Selection. " << endl;
            cout << "\033[2J\033[1;1H";
            break;

        } // end switch statement
    } while (!((department == 'Q') || (department == 'q'))); // last of the do-while loop. Q or q break from loop.

    system("pause");
    return 0;
} // main bracket


Here’s the assignment for Lab3. The next class session will show us .

Public Class frmCompare

    '----JDS-----------------------
    'CREATED:    10/15/2014
    'CREATED BY: James Strickland
    'CLASS:      COP2010 - 090898
    'PURPOSE:    Write a Windows Application
    '            program that inputs
    '            three different integers
    '            and displays results
    '            in a listbox
    '----JDS-----------------------

    ' Declare variables
    ' inum=InputNumber
    Dim inum1, inum2, inum3 As Integer

    ' onum=OutputNumber
    Dim onum1, onum2, onum3, max, min As Integer

    Private Sub frmCompare_Load(sender As Object, _
                                e As EventArgs) _
                            Handles MyBase.Load

        ' Hide the "About" label at form load
        lblAbout.Visible = False

    End Sub


    Private Sub btnGo_Click(sender As Object, _
                        e As EventArgs) _
                        Handles btnExe.Click

        ' The following code is executed 
        ' when the EXECUTE button is pressed

        ' Get the users 3 numbers and load
        ' them into the 3 input variables
        inum1 = txtInput1.Text
        inum2 = txtInput2.Text
        inum3 = txtInput3.Text

        ' Clear list box encase user wants to 
        ' repeat program without scrolling 
        ' down listbox.
        LstBoxResults.Items.Clear()

        ' Display numbers as user entered them
        ' seperated by comma
        LstBoxResults.Items.Add("Numbers in User Order:")
        LstBoxResults.Items.Add(inum1 & ", " & inum2 & ", " & inum3)
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Sum of users entered numbers
        LstBoxResults.Items.Add("Sum of numbers:") ' Displays to user
        LstBoxResults.Items.Add(inum1 + inum2 + inum3) ' does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Average of numbers
        LstBoxResults.Items.Add("Average of Numbers:") ' Displays to user
        LstBoxResults.Items.Add((inum1 + inum2 + inum3) \ 3) ' does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Product of numbers
        LstBoxResults.Items.Add("Product of numbers:") ' Displays to user
        LstBoxResults.Items.Add(inum1 * inum2 * inum3) ' Does the math
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Largest of the 3 numbers
        LstBoxResults.Items.Add("Largest of the 3:")
        max = inum1 ' Init variable mas a first number entered, the compare below...

        If inum2 > max Then
            max = inum2 ' inum2 greater than max, init max as inum2 (inum2 is smaller)
        End If

        If inum3 > max Then
            max = inum3 ' inum3 greater than max, init max as inum3 (inum3 is smaller)
        End If

        LstBoxResults.Items.Add(max)
        LstBoxResults.Items.Add("") ' simply creates a space between answers

        ' Display Smallest of the 3 numbers
        LstBoxResults.Items.Add("Smallest of the 3:")
        min = inum1 ' init min as inum1

        If inum2 < min Then
            min = inum2 ' inum2 less than min, init min as inum2 (inum2 is bigger)
        End If

        If inum3 < min Then
            min = inum3 ' inum3 less than min, init min as inum3 (inum3 is bigger)
        End If

        LstBoxResults.Items.Add(min) ' Display results of min
        LstBoxResults.Items.Add("") ' simply creates a space between answers

    End Sub

    ' Close/Exit the program
    Private Sub btnExit_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles btnExit.Click
        Close()

    End Sub



    Private Sub btnAbout_Click(sender As Object, _
                               e As EventArgs) _
                               Handles btnAbout.Click
        ' The below code hides the form content and 
        ' displays information about the programmer
        ' (when the user presses the "about" button)
        ' which happens to be me. For those who does
        ' not know me, I am a big deal around here..
        ' I mean, I didn't want to say nuthin.......

        ' Clear Form
        btnExe.Visible = False
        lblEnterNumbers.Visible = False
        lblInstruction.Visible = False
        txtInput1.Visible = False
        txtInput2.Visible = False
        txtInput3.Visible = False
        LstBoxResults.Visible = False

        ' About Programmer
        lblAbout.Visible = True

    End Sub

End Class