Last active
May 31, 2026 10:29
-
-
Save shakna-israel/7fd5da01631b36d5ed2d605c6e25ed33 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| import tkinter as tk | |
| from tkinter import messagebox | |
| import os | |
| import stat | |
| def create_desktop_file(): | |
| url = url_entry.get().strip() | |
| title = title_entry.get().strip() | |
| if not url or not title: | |
| messagebox.showerror("Error", "Please enter both a URL and a title.") | |
| return | |
| if not url.startswith(("http://", "https://")): | |
| url = "https://" + url | |
| safe_name = title.replace(" ", "_").replace("/", "-") | |
| filepath = os.path.expanduser(f"~/Desktop/{safe_name}.desktop") | |
| content = f"""[Desktop Entry] | |
| Encoding=UTF-8 | |
| Version=1.0 | |
| Type=Application | |
| Terminal=false | |
| Exec=xdg-open {url} | |
| Name={title} | |
| Icon=web-browser | |
| """ | |
| try: | |
| with open(filepath, "w") as f: | |
| f.write(content) | |
| st = os.stat(filepath) | |
| os.chmod(filepath, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) | |
| messagebox.showinfo("Success", f"Shortcut created:\n{filepath}") | |
| url_entry.delete(0, tk.END) | |
| title_entry.delete(0, tk.END) | |
| url_entry.insert(0, "https://") | |
| except Exception as e: | |
| messagebox.showerror("Error", f"Could not write file:\n{e}") | |
| root = tk.Tk() | |
| root.title("Web Shortcut Creator") | |
| root.resizable(False, False) | |
| frame = tk.Frame(root, padx=16, pady=16) | |
| frame.pack() | |
| tk.Label(frame, text="URL").grid(row=0, column=0, sticky="w") | |
| url_entry = tk.Entry(frame, width=48) | |
| url_entry.grid(row=1, column=0, sticky="ew", pady=(0, 8)) | |
| url_entry.insert(0, "https://") | |
| tk.Label(frame, text="Name").grid(row=2, column=0, sticky="w") | |
| title_entry = tk.Entry(frame, width=48) | |
| title_entry.grid(row=3, column=0, sticky="ew", pady=(0, 12)) | |
| tk.Button(frame, text="Create .desktop Shortcut", command=create_desktop_file).grid(row=4, column=0, sticky="ew") | |
| root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment