Created
October 15, 2025 11:23
-
-
Save fivetide/4797e9cbd187470b1b53605b99d92a92 to your computer and use it in GitHub Desktop.
tuxedo profile tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env bash | |
| # File: /home/bjoern/.local/bin/tuxedo-profile | |
| # Check if jq is installed | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is required but not installed. Please install it first." | |
| echo "You can install it with: sudo apt install jq" | |
| exit 1 | |
| fi | |
| # Function to get profiles JSON | |
| get_profiles() { | |
| local raw_output | |
| raw_output=$(gdbus call --system --dest com.tuxedocomputers.tccd \ | |
| --object-path /com/tuxedocomputers/tccd \ | |
| --method com.tuxedocomputers.tccd.GetProfilesJSON) | |
| # Extract the JSON part from the DBus output | |
| # The output is in the format ('[JSON_ARRAY]',) | |
| local json_part | |
| json_part=$(echo "$raw_output" | sed -E "s/^\('(.*)'\,\)$/\1/") | |
| echo "$json_part" | |
| } | |
| # Function to get active profile JSON | |
| get_active_profile() { | |
| local raw_output | |
| raw_output=$(gdbus call --system --dest com.tuxedocomputers.tccd \ | |
| --object-path /com/tuxedocomputers/tccd \ | |
| --method com.tuxedocomputers.tccd.GetActiveProfileJSON) | |
| # Extract the JSON part from the DBus output | |
| local json_part | |
| json_part=$(echo "$raw_output" | sed -E "s/^\('(.*)'\,\)$/\1/") | |
| echo "$json_part" | |
| } | |
| # Function to set profile by ID | |
| set_profile() { | |
| local profile_id="$1" | |
| gdbus call --system --dest com.tuxedocomputers.tccd \ | |
| --object-path /com/tuxedocomputers/tccd \ | |
| --method com.tuxedocomputers.tccd.SetTempProfileById \ | |
| -- "$profile_id" | |
| # Check the return value to confirm success | |
| local result=$? | |
| if [ $result -eq 0 ]; then | |
| echo "Profile '$profile_id' activated successfully." | |
| else | |
| echo "Failed to activate profile '$profile_id'." | |
| fi | |
| } | |
| # Function to list profiles | |
| list_profiles() { | |
| local profiles_json="$1" | |
| local active_profile_json="$2" | |
| local active_profile_id | |
| # Extract the active profile ID | |
| active_profile_id=$(echo "$active_profile_json" | jq -r '.id') | |
| echo "Available TUXEDO Profiles:" | |
| echo "==========================" | |
| # Parse and display each profile with active indicator | |
| echo "$profiles_json" | jq -r --arg active_id "$active_profile_id" '.[] | | |
| (if .id == $active_id then "* " else " " end) + | |
| "ID: " + .id + "\n" + | |
| " Name: " + .name + "\n" + | |
| " Description: " + .description + | |
| (if .cpu.governor then "\n CPU Governor: " + .cpu.governor else "" end) + | |
| (if .fan.fanProfile then "\n Fan Profile: " + .fan.fanProfile else "" end) + "\n"' | |
| } | |
| # Function to show interactive menu | |
| show_menu() { | |
| local profiles_json="$1" | |
| local active_profile_json="$2" | |
| local active_profile_id | |
| # Extract the active profile ID | |
| active_profile_id=$(echo "$active_profile_json" | jq -r '.id') | |
| echo "Select a profile to activate:" | |
| echo "============================" | |
| # Create array of profile IDs and names | |
| mapfile -t profile_ids < <(echo "$profiles_json" | jq -r '.[] | .id') | |
| mapfile -t profile_names < <(echo "$profiles_json" | jq -r '.[] | .name') | |
| # Display menu with active indicator | |
| for i in "${!profile_ids[@]}"; do | |
| if [ "${profile_ids[$i]}" == "$active_profile_id" ]; then | |
| echo "$((i+1)). ${profile_names[$i]} (${profile_ids[$i]}) [ACTIVE]" | |
| else | |
| echo "$((i+1)). ${profile_names[$i]} (${profile_ids[$i]})" | |
| fi | |
| done | |
| # Get user selection | |
| echo -n "Enter number (or q to quit): " | |
| read -r selection | |
| # Process selection | |
| if [[ "$selection" == "q" ]]; then | |
| exit 0 | |
| elif [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le "${#profile_ids[@]}" ]; then | |
| set_profile "${profile_ids[$((selection-1))]}" | |
| else | |
| echo "Invalid selection. Please try again." | |
| echo | |
| show_menu "$profiles_json" "$active_profile_json" | |
| fi | |
| } | |
| # Function to set profile by name | |
| set_profile_by_name() { | |
| local profile_name="$1" | |
| gdbus call --system --dest com.tuxedocomputers.tccd \ | |
| --object-path /com/tuxedocomputers/tccd \ | |
| --method com.tuxedocomputers.tccd.SetTempProfile \ | |
| -- "$profile_name" | |
| # Check the return value to confirm success | |
| local result=$? | |
| if [ $result -eq 0 ]; then | |
| echo "Profile '$profile_name' activated successfully." | |
| else | |
| echo "Failed to activate profile '$profile_name'." | |
| fi | |
| } | |
| # Function to show current active profile | |
| show_active_profile() { | |
| local active_profile_json="$1" | |
| echo "Current Active Profile:" | |
| echo "=======================" | |
| echo "$active_profile_json" | jq -r ' | |
| "ID: " + .id + "\n" + | |
| "Name: " + .name + "\n" + | |
| "Description: " + .description + | |
| (if .cpu.governor then "\nCPU Governor: " + .cpu.governor else "" end) + | |
| (if .fan.fanProfile then "\nFan Profile: " + .fan.fanProfile else "" end)' | |
| } | |
| # Main execution | |
| profiles_json=$(get_profiles) | |
| active_profile_json=$(get_active_profile) | |
| # Process command line arguments | |
| if [ "$1" == "list" ]; then | |
| list_profiles "$profiles_json" "$active_profile_json" | |
| elif [ "$1" == "current" ]; then | |
| show_active_profile "$active_profile_json" | |
| elif [ "$1" == "set" ] && [ -n "$2" ]; then | |
| # Check if profile ID exists | |
| if echo "$profiles_json" | jq -e --arg id "$2" '.[] | select(.id == $id)' > /dev/null; then | |
| set_profile "$2" | |
| else | |
| echo "Error: Profile ID '$2' not found." | |
| echo "Available profile IDs:" | |
| echo "$profiles_json" | jq -r '.[] | .id' | sed 's/^/- /' | |
| fi | |
| elif [ "$1" == "set-name" ] && [ -n "$2" ]; then | |
| # Set profile by name | |
| set_profile_by_name "$2" | |
| else | |
| # No valid arguments, show active profile and interactive menu | |
| show_active_profile "$active_profile_json" | |
| echo | |
| list_profiles "$profiles_json" "$active_profile_json" | |
| echo | |
| show_menu "$profiles_json" "$active_profile_json" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment