diff options
| -rw-r--r-- | .local/share/python-dateTimeSetter/dateTime.py | 87 | ||||
| -rwxr-xr-x | .local/share/scripts/GUI-dateTime | 3 | ||||
| -rwxr-xr-x | .local/share/scripts/dateTime.sh | 36 | ||||
| -rwxr-xr-x | .local/share/scripts/setTime.sh | 46 |
4 files changed, 126 insertions, 46 deletions
diff --git a/.local/share/python-dateTimeSetter/dateTime.py b/.local/share/python-dateTimeSetter/dateTime.py new file mode 100644 index 0000000..186c671 --- /dev/null +++ b/.local/share/python-dateTimeSetter/dateTime.py @@ -0,0 +1,87 @@ +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, GLib +import subprocess + +class dateTimeSetter(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self, title="dateTimeSetter") + self.set_border_width(10) + self.set_default_size(400, 300) + + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) + self.add(vbox) + + # Automatic time setting checkbox + automatic_time_label = Gtk.Label(label="Set the date, time, and timezone automatically?") + vbox.pack_start(automatic_time_label, False, False, 0) + + self.automatic_time_check = Gtk.CheckButton(label="Yes") + self.automatic_time_check.connect("toggled", self.on_automatic_time_toggled) + vbox.pack_start(self.automatic_time_check, False, False, 0) + + # Date and time entry fields + date_label = Gtk.Label(label="Enter the desired date (format: YYYY-MM-DD):") + vbox.pack_start(date_label, False, False, 0) + + self.date_entry = Gtk.Entry() + vbox.pack_start(self.date_entry, False, False, 0) + + time_label = Gtk.Label(label="Enter the desired time (format: HH:MM:SS):") + vbox.pack_start(time_label, False, False, 0) + + self.time_entry = Gtk.Entry() + vbox.pack_start(self.time_entry, False, False, 0) + + # Timezone entry field + timezone_label = Gtk.Label(label="Enter the desired timezone (e.g., America/New_York):") + vbox.pack_start(timezone_label, False, False, 0) + + self.timezone_entry = Gtk.Entry() + vbox.pack_start(self.timezone_entry, False, False, 0) + + # Apply button + apply_button = Gtk.Button(label="Apply") + apply_button.connect("clicked", self.on_apply_clicked) + vbox.pack_start(apply_button, False, False, 0) + + def on_automatic_time_toggled(self, button): + if button.get_active(): + self.date_entry.set_sensitive(False) + self.time_entry.set_sensitive(False) + self.timezone_entry.set_sensitive(False) + else: + self.date_entry.set_sensitive(True) + self.time_entry.set_sensitive(True) + self.timezone_entry.set_sensitive(True) + + def on_apply_clicked(self, button): + automatic_time = self.automatic_time_check.get_active() + + if automatic_time: + subprocess.run(["timedatectl", "set-ntp", "true"]) + print("Automatic time synchronization using NTP initiated.") + + automatic_timezone_output = subprocess.run(["curl", "--fail", "https://ipapi.co/timezone"], capture_output=True, text=True) + automatic_timezone = automatic_timezone_output.stdout.strip() + + if automatic_timezone: + subprocess.run(["timedatectl", "set-timezone", automatic_timezone]) + print("Automatic timezone setting complete.") + else: + print("Automatic timezone setting failed. Please set the timezone manually.") + else: + date_input = self.date_entry.get_text() + time_input = self.time_entry.get_text() + timezone_input = self.timezone_entry.get_text() + + subprocess.run(["timedatectl", "set-ntp", "false"]) + subprocess.run(["timedatectl", "set-time", f"{date_input} {time_input}"]) + subprocess.run(["timedatectl", "set-timezone", timezone_input]) + print("Manual date, time, and timezone setting complete.") + + +win = dateTimeSetter() +win.connect("destroy", Gtk.main_quit) +win.show_all() +Gtk.main() diff --git a/.local/share/scripts/GUI-dateTime b/.local/share/scripts/GUI-dateTime new file mode 100755 index 0000000..ad14ad2 --- /dev/null +++ b/.local/share/scripts/GUI-dateTime @@ -0,0 +1,3 @@ +#!/bin/sh + +python ~/.local/share/python-dateTimeSetter/dateTime.py diff --git a/.local/share/scripts/dateTime.sh b/.local/share/scripts/dateTime.sh new file mode 100755 index 0000000..427ed6a --- /dev/null +++ b/.local/share/scripts/dateTime.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# Prompt the user for automatic time setting +echo "Do you want to set the date, time, and timezone automatically? [y/n]" +read -r automatic_time_input + +if [ "$automatic_time_input" = "y" ] || [ "$automatic_time_input" = "Y" ]; then + # Synchronize the system time automatically using NTP + timedatectl set-ntp true + echo "Automatic time synchronization using NTP initiated." + automatic_timezone=$(curl --fail https://ipapi.co/timezone 2>/dev/null) + if [ -n "$automatic_timezone" ]; then + timedatectl set-timezone "$automatic_timezone" + echo "Automatic timezone setting complete." + else + echo "Automatic timezone setting failed. Please set the timezone manually." + fi +else + # Prompt the user for date and time input + echo "Enter the desired date (format: YYYY-MM-DD):" + read -r date_input + echo "Enter the desired time (format: HH:MM:SS):" + read -r time_input + # Prompt the user for timezone input + echo "Enter the desired timezone (e.g., America/New_York):" + read -r timezone_input + + # Override NTP setting + timedatectl set-ntp false + + # Set the system date and time + timedatectl set-time "$date_input $time_input" + # Set the system timezone + timedatectl set-timezone "$timezone_input" + echo "Manual date and time setting complete." +fi diff --git a/.local/share/scripts/setTime.sh b/.local/share/scripts/setTime.sh deleted file mode 100755 index 920e7ed..0000000 --- a/.local/share/scripts/setTime.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh - -# Prompt the user for automatic timezone setting -echo "Do you want to automatically set the timezone based on your location? [y/n]" -read -r automatic_timezone_input - -if [ "$automatic_timezone_input" = "y" ] || [ "$automatic_timezone_input" = "Y" ]; then - # Set the system timezone automatically based on location - automatic_timezone=$(curl --fail https://ipapi.co/timezone 2>/dev/null) - if [ -n "$automatic_timezone" ]; then - sudo timedatectl set-timezone "$automatic_timezone" - echo "Automatic timezone setting complete." - else - echo "Automatic timezone setting failed. Please set the timezone manually." - fi -else - # Prompt the user for timezone input - echo "Enter the desired timezone (e.g., America/New_York):" - read -r timezone_input - - # Set the system timezone - sudo timedatectl set-timezone "$timezone_input" -fi - -# Prompt the user for automatic time setting -echo "Do you want to set the time automatically? [y/n]" -read -r automatic_time_input - -if [ "$automatic_time_input" = "y" ] || [ "$automatic_time_input" = "Y" ]; then - # Synchronize the system time automatically using NTP - sudo timedatectl set-ntp true - echo "Automatic time synchronization using NTP initiated." -else - # Prompt the user for date and time input - echo "Enter the desired date (format: YYYY-MM-DD):" - read -r date_input - echo "Enter the desired time (format: HH:MM:SS):" - read -r time_input - - # Override NTP setting - sudo timedatectl set-ntp false - - # Set the system date and time - sudo timedatectl set-time "$date_input $time_input" - echo "Manual date and time setting complete." -fi
\ No newline at end of file |
