Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
import gi.repository
import logging
import os
import os.path
import psutil
import signal
import subprocess
import sys
gi.require_version('Gtk', '3.0')
gi.require_version('Wnck', '3.0')
gi.require_version('Budgie', '1.0')
from gi.repository import Budgie, GObject, Gtk, Wnck
class applemenunew(GObject.GObject, Budgie.Plugin):
__gtype_name__ = "applemenunew"
def __int__(self):
def do_get_panel_widget(self, uuid):
return applemenunewApplet(uuid)
def get_active_window():
global b
screen = Wnck.Screen.get_default()
active_window = screen.get_active_window()
pid = active_window.get_pid()
process = psutil.Process(pid)
process_name =
with open("/proc/{pid}/cmdline".format(pid=pid)) as f:
active_window_name = os.path.basename(
a = process_name.replace("-", " ")
b = a.title()
if b != "Nemo Desktop":
a = process_name.replace("-", " ")
b = a.title()
b = " "
return pid, b
t1, t2 = get_active_window()
class applemenunewApplet(Budgie.Applet):
def __init__(self, uuid):
Budgie.Applet.__init__(self) = Gtk.EventBox()"Apple Menu")
img = Gtk.Image.new_from_icon_name("apple", Gtk.IconSize.MENU) = Gtk.Menu()
def run_command(self, menuitem):
def run_command1(self, menuitem):
subprocess.Popen(["gnome-control-center", "wifi"])
def run_command2(self, menuitem):["gnome-software"])
def run_command4(self, menuitem):
t1, t2 = get_active_window()
os.kill(int(t1), signal.SIGTERM)
def run_command5(self, menuitem):["systemctl", "suspend"])
def run_command6(self, menuitem):["gnome-session-quit", "--reboot"])
def run_command7(self, menuitem):["gnome-session-quit", "--power-off"])
def run_command8(self, menuitem):["gnome-session-quit"])
def create_menu(self):
global item5
item1 = Gtk.MenuItem('About This PC')
item1.connect("activate", self.run_command)
item2 = Gtk.MenuItem('System Settings...')
item2.connect("activate", self.run_command1)
item3 = Gtk.MenuItem('Software... ')
item3.connect("activate", self.run_command2)
item4 = Gtk.MenuItem('Recent Items')
re = Gtk.RecentChooserMenu()
re.connect('item-activated', self.on_item_activated)
t1, t2 = get_active_window()
item5 = Gtk.MenuItem('Force Quit...' + t2)
item6 = Gtk.MenuItem('Sleep')
item6.connect("activate", self.run_command5)
item7 = Gtk.MenuItem('Restart...')
item7.connect("activate", self.run_command6)
item8 = Gtk.MenuItem('ShutDown...')
item8.connect("activate", self.run_command7)
item9 = Gtk.MenuItem('LogOut\t\t\t\t\tCtrl Alt Del')
item9.connect("activate", self.run_command8)
for item in [item1, item2, item3, item4, item5, item6, item7, item8, item9]:
sep = Gtk.SeparatorMenuItem()
sep1 = Gtk.SeparatorMenuItem()
sep2 = Gtk.SeparatorMenuItem()
sep3 = Gtk.SeparatorMenuItem()
sep4 = Gtk.SeparatorMenuItem(), 1), 4), 6), 8), 12)"button-press-event", self.popup_menu)
def popup_menu(self, *args):, None, None, None, 0, Gtk.get_current_event_time())
global item5
t1, t2 = get_active_window()
item5 = Gtk.MenuItem('Force Quit...\t\t' + t2)
item5.connect("activate", self.run_command4), 7)
def on_item_activated(self, re):
recentitem = re.get_current_item()
if recentitem:['xdg-open', recentitem.get_uri()])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment