def handleQuery(query): stripped = query.string.strip().lower() if stripped: results = [] for line in subprocess.check_output(['wmctrl', '-l', '-x']).splitlines(): win = Window(*parseWindow(line)) if win.desktop == "-1": continue win_instance, win_class = win.wm_class.replace(' ', '-').split('.') matches = [ win_instance.lower(), win_class.lower(), win.wm_name.lower() ] if any(stripped in match for match in matches): iconPath = iconLookup(win_instance) if iconPath == "": iconPath = iconLookup(win_class.lower()) results.append(Item(id="%s%s" % (__prettyname__, win.wm_class), icon=iconPath, text="%s - <i>Desktop %s</i>" % (win_class.replace('-',' '), win.desktop), subtext=win.wm_name, actions=[ProcAction("Switch Window", ["wmctrl", '-i', '-a', win.wid] ), ProcAction("Move window to this desktop", ["wmctrl", '-i', '-R', win.wid] ), ProcAction("Close the window gracefully.", ["wmctrl", '-c', win.wid])])) return results
def make_item(engine, query=None): if query is not None: return Item( text=query, subtext=engine["name"], icon=iconLookup(engine["icon"]), actions=[ FuncAction( "Search {}".format(engine["name"]), lambda: webbrowser.open(engine["search"].format(query)), ) ], ) else: return Item( text=engine["shortcut"], subtext=engine["name"], icon=iconLookup(engine["icon"]), )
def handleQuery(query): if not query.string.strip(): defaultResults = [] for line in subprocess.check_output(['wmctrl', '-l', '-x']).splitlines(): win = Window(*[token.decode() for token in line.split(None, 4)]) if "albert" in win.wm_name and "Albert" in win.wm_name: continue if win.desktop != "-1": defaultResults.append(Item(id="%s%s" % (__prettyname__, win.wm_class), icon=iconLookup( win.wm_class.split('.')[1].capitalize()), text="%s" % (win.wm_class.split('.')[1].capitalize()), subtext=win.wm_name, actions=[ProcAction("Switch Window", ["wmctrl", '-i', '-a', win.wid]), ProcAction("Move window to this desktop", ["wmctrl", '-i', '-R', win.wid]), ProcAction("Close the window gracefully.", ["wmctrl", '-c', win.wid])])) return defaultResults stripped = query.string.strip().lower() if stripped: results = [] for line in subprocess.check_output(['wmctrl', '-l', '-x']).splitlines(): win = Window(*[token.decode() for token in line.split(None, 4)]) if "albert" in win.wm_name and "Albert" in win.wm_name: continue if win.desktop != "-1" and stripped in win.wm_name.lower(): results.append(Item(id="%s%s" % (__prettyname__, win.wm_class), icon=iconLookup( win.wm_class.split('.')[1].capitalize()), text="%s" % (win.wm_class.split('.')[1].capitalize()), subtext=win.wm_name, actions=[ProcAction("Switch Window", ["wmctrl", '-i', '-a', win.wid]), ProcAction("Move window to this desktop", ["wmctrl", '-i', '-R', win.wid]), ProcAction("Close the window gracefully.", ["wmctrl", '-c', win.wid])])) return results
def buildFromDir(d): with os.scandir(d) as it: for entry in it: if not entry.name.endswith(".desktop"): continue desktopf = DesktopEntry.DesktopEntry(entry.path) icon = iconLookup(desktopf.getIcon()) iconMap[entry.name[:-8].lower( )] = icon # Get rid of .desktop suffix wm_class = desktopf.getStartupWMClass() if wm_class != "": iconMap[wm_class.lower()] = icon
def multipleIconLookup(identifiers): # Lookup icon using map icon = "" for ident in identifiers: icon = iconMap.get(ident.strip().lower(), "") if icon != "": return icon # Fallback to trying wm_class and wm_name directly for ident in identifiers: icon = iconLookup(ident.strip().lower()) if icon != "": return icon return icon
__iid__ = "PythonInterface/v0.1" __prettyname__ = "E-J Dictionary" __version__ = "1.0" __trigger__ = "ej " __author__ = "Tetsutaro Maruyama" __dependencies__ = ["ag"] __dictionary_file__ = "/usr/local/share/dict/ej-gene95.txt" __max_candidate__ = 5 if which("ag") is None: raise Exception("'ag' is not in $PATH.") if not os.path.exists(__dictionary_file__): raise Exception("dictionary_file is not exists") icon = iconLookup('accessories-dictionary') def _compose_ag_command(query): if query.startswith('"') and query.endswith('"'): kwd = query[1:-1] pad = "\t" elif query.startswith("'") and query.endswith("'"): kwd = query[1:-1] pad = "\t" else: kwd = query pad = '' return ' '.join([ 'ag', '-S', '--nocolor', '--nonumber', '-m', '%d' % __max_candidate__,
import subprocess import sys from fuzzywuzzy import process import albertv0 as v0 import shutil __iid__ = "PythonInterface/{{ cookiecutter.albert_plugin_interface }}" __prettyname__ = "{{ cookiecutter.plugin_short_description }}" __version__ = "{{ cookiecutter.version }}" __trigger__ = "{{ cookiecutter.plugin_name }} " __author__ = "{{ cookiecutter.author }}" __dependencies__ = [] __homepage__ = "{{ cookiecutter.repo_base_url }}/{{ cookiecutter.repo_name }}" icon_path = v0.iconLookup("{{ cookiecutter.plugin_name }}") if not icon_path: icon_path = os.path.join(os.path.dirname(__file__), "{{ cookiecutter.plugin_name }}") cache_path = Path(v0.cacheLocation()) / "{{ cookiecutter.plugin_name }}" config_path = Path(v0.configLocation()) / "{{ cookiecutter.plugin_name }}" data_path = Path(v0.dataLocation()) / "{{ cookiecutter.plugin_name }}" # plugin main functions ----------------------------------------------------------------------- def initialize(): # Called when the extension is loaded (ticked in the settings) - blocking # create plugin locations for p in (cache_path, config_path, data_path):
Synopsis: <trigger> <query>""" from shutil import which from subprocess import run from albertv0 import Item, ProcAction, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "GoldenDict" __version__ = "1.0" __trigger__ = "gd " __author__ = "Manuel Schneider" __dependencies__ = ["goldendict"] if which("goldendict") is None: raise Exception("'goldendict' is not in $PATH.") iconPath = iconLookup('goldendict') def handleQuery(query): if query.isTriggered: return Item(id=__prettyname__, icon=iconPath, text=__prettyname__, subtext="Look up '%s' using %s" % (query.string, __prettyname__), completion=query.rawString, actions=[ProcAction("Start query in %s" % __prettyname__, ["goldendict", query.string])])
import urllib.error import urllib.parse import urllib.request from time import sleep from albertv0 import (ClipAction, Item, ProcAction, UrlAction, configLocation, iconLookup) __iid__ = "PythonInterface/v0.2" __prettyname__ = "MultiTranslate" __version__ = "1.2" __trigger__ = "mtr " __author__ = "David Britt" __dependencies__ = [] iconPath = iconLookup('config-language') if not iconPath: iconPath = ":python_module" ua = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36" urltmpl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=%s&dt=t&q=%s" urlbrowser = "https://translate.google.com/#auto/%s/%s" configurationFileName = "language_config.json" configuration_directory = os.path.join(configLocation(), __prettyname__) language_configuration_file = os.path.join(configuration_directory, configurationFileName) languages = [] def initialize(): if os.path.exists(language_configuration_file):
import json import re import time from os import path from urllib.parse import urlencode from urllib.request import Request, urlopen from albertv0 import Item, UrlAction, iconLookup, critical, debug, info __iid__ = 'PythonInterface/v0.1' __prettyname__ = 'Youtube' __version__ = '1.1' __trigger__ = 'yt ' __author__ = 'Manuel Schneider' __icon__ = iconLookup('youtube') # path.dirname(__file__) + '/icons/YouTube.png' DATA_REGEX = re.compile(r'^\s*(var\s|window\[")ytInitialData("\])?\s*=\s*(.*)\s*;\s*$', re.MULTILINE) HEADERS = { 'User-Agent': ( 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)' ' Chrome/62.0.3202.62 Safari/537.36' ) } def handleQuery(query): if query.isTriggered and query.string.strip(): # avoid rate limiting time.sleep(0.2)
def handleQuery(query): if query.isTriggered: stripped = query.string if stripped.startswith(__trigger__): stripped = query.string[len(__trigger__) :] return [Item(text=iconLookup(stripped), icon=iconLookup(stripped))]
from pathlib import Path import sys import os import zoopla as z import albertv0 as v0 __iid__ = "PythonInterface/v0.2" __prettyname__ = "Zoopla - Search Properties" __version__ = "0.1.0" __trigger__ = "z " __author__ = "Nikos Koukis" __dependencies__ = [] __homepage__ = "https://github.com/bergercookie/zoopla-albert-plugin" iconPath = v0.iconLookup("zoopla") if not iconPath: iconPath = os.path.join(os.path.dirname(__file__), "zoopla") settings_path = Path(v0.cacheLocation()) / "zoopla" api_key = "khagqa497wsgfa5ya35rwfnt" zoopla = z.Zoopla(api_key=api_key) str_to_key = { "sale": "listing_status", "rent": "listing_status", } str_to_actual_name = { "sale": "sale", "rent": "rent",
from fuzzywuzzy import process import albertv0 as v0 __iid__ = "PythonInterface/v0.2" __prettyname__ = "GMaps - Launch route planner" __version__ = "0.1.0" __trigger__ = "gmaps " __author__ = "Nikos Koukis" __dependencies__ = [] __homepage__ = ( "https://github.com/bergercookie/awesome-albert-plugins/blob/master/plugins//gmaps" ) icon_path = v0.iconLookup("gmaps") if not icon_path: icon_path = os.path.join(os.path.dirname(__file__), "gmaps") cache_path = Path(v0.cacheLocation()) / "gmaps" config_path = Path(v0.configLocation()) / "gmaps" data_path = Path(v0.dataLocation()) / "gmaps" gmaps_exe = Path(__file__).parent / "gmaps-cli" / "gmaps-cli.py" available_means = ["walk", "drive", "bicycle", "fly", "transit"] default_means = "transit" # plugin main functions ----------------------------------------------------------------------- def initialize():
import re from shutil import which from albertv0 import ProcAction, Item, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "Godot Projects" __version__ = "1.0" __trigger__ = "godot " __author__ = "Patrick Wuttke" __dependencies__ = [] if which("godot") is None: raise Exception("'godot' is not in $PATH.") iconPath = iconLookup('godot') project_path_regex = re.compile( '^(?:"projects\\/[^"]*"|projects\\/\\S*)\\s*=\\s*"(?P<path>[^"]*)"$') project_name_regex = re.compile('^config\\/name\\s*=\\s*"(?P<value>[^"]*)"$') project_icon_regex = re.compile('^config\\/icon\\s*=\\s*"(?P<value>[^"]*)"$') projects_file = os.path.join(os.environ['HOME'], '.config/godot/editor_settings-3.tres') mtime = 0 projects = [] def updateProjects(): global mtime try: new_mtime = os.path.getmtime(projects_file)
from collections import namedtuple from albertv0 import Item, iconLookup, ProcAction __iid__ = "PythonInterface/v0.1" __prettyname__ = "Network Manager VPN" __version__ = "0.1" __trigger__ = "vpn " __author__ = "Reetobrata Chatterjee" __dependencies__ = ["networkmanager", "networkmanager-openvpn"] if which("nmcli") is None: raise Exception("'nmcli' is not in $PATH.") Connection = namedtuple("Connection", ["name", "id", "type", "interface"]) NET_ICON = iconLookup("preferences-system-network") def get_vpns(): vpns = [] for line in (subprocess.check_output(["nmcli", "-t", "c", "show" ]).decode("utf-8").splitlines()): conn = Connection(*(line.split(":"))) if conn.type == "vpn": vpns.append(conn) return vpns def make_vpn_item(vpn): subtext = None
from shutil import which from tempfile import NamedTemporaryFile from albertv0 import ClipAction, Item, iconLookup __iid__ = 'PythonInterface/v0.1' __prettyname__ = 'Mathematica eval' __version__ = '1.0' __trigger__ = 'mma ' __author__ = 'Asger Hautop Drewsen' __dependencies__ = ['mathematica'] if not which('wolframscript'): raise Exception("`wolframscript` is not in $PATH.") ICON_PATH = iconLookup('wolfram-mathematica') def handleQuery(query): if not query.isTriggered: return item = Item(completion=query.rawString, icon=ICON_PATH) stripped = query.string.strip() if stripped: with NamedTemporaryFile() as f: f.write(bytes(stripped, 'utf-8')) f.flush() output = subprocess.check_output( ['wolframscript', '-print', '-f', f.name])
from shutil import which from albertv0 import FuncAction, Item, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "SCReenshOT utility" __version__ = "1.0" __trigger__ = "scrot " __author__ = "Benedict Dudel" __dependencies__ = ["scrot", "xclip"] for dep in __dependencies__: if not which(dep): raise Exception("'%s' is not in $PATH." % dep) iconPath = iconLookup("camera-photo") def handleQuery(query): if query.isTriggered: return [ Item(id="%s-whole-screen" % __prettyname__, icon=iconPath, text="Screen", subtext="Take a screenshot of the whole screen", actions=[ FuncAction("Take screenshot of whole screen", lambda: doScreenshot([])), FuncAction("Take screenshot of multiple displays", lambda: doScreenshot(["--multidisp"])), ]),
Synopsis: <trigger> <filter>""" import os from signal import SIGKILL, SIGTERM from albertv0 import FuncAction, Item, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "Kill Process" __version__ = "1.4" __trigger__ = "kill " __author__ = "Benedict Dudel, Manuel Schneider" __dependencies__ = [] iconPath = iconLookup('process-stop') def handleQuery(query): if query.isTriggered: results = [] uid = os.getuid() for dir_entry in os.scandir('/proc'): try: if dir_entry.name.isdigit() and dir_entry.stat().st_uid == uid: proc_command = open(os.path.join(dir_entry.path, 'comm'), 'r').read().strip() if query.string in proc_command: proc_cmdline = open( os.path.join(dir_entry.path, 'cmdline'), 'r').read().strip().replace("\0", " ")
from shutil import which from albertv0 import Item, TermAction, UrlAction, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "Locate" __version__ = "1.0" __trigger__ = "'" __author__ = "Manuel Schneider" __dependencies__ = ['locate'] if which("locate") is None: raise Exception("'locate' is not in $PATH.") for iconName in ["system-search", "search", "text-x-generic"]: iconPath = iconLookup(iconName) if iconPath: break def handleQuery(query): results = [] if query.isTriggered: if len(query.string) > 2: pattern = re.compile(query.string, re.IGNORECASE) proc = subprocess.Popen(['locate', '-bi', query.string], stdout=subprocess.PIPE) for line in proc.stdout: path = line.decode().strip() basename = os.path.basename(path) results.append(
""" import os from datetime import datetime from subprocess import call from albertv0 import iconLookup, Item, FuncAction __iid__ = "PythonInterface/v0.1" __prettyname__ = "Card" __version__ = "0.1" __trigger__ = "card" __author__ = "alswl" __dependencies__ = [] iconPath = iconLookup('gvim') DIR_PATH = 'Desktop/md/card' APP = "gvim" def handleQuery(query): if not query.isTriggered: return results = [] results.append( Item(id="card", icon=iconPath, text="Card", subtext="open today card", completion='card',
# -*- coding: utf-8 -*- """Open virtual trash location. This extension provides a single item which opens the systems virtual trash \ location in your default file manager. Synopsis: <trigger>""" import re from albertv0 import Item, UrlAction, iconLookup __iid__ = "PythonInterface/v0.1" __prettyname__ = "Trash" __version__ = "1.0" __author__ = "Manuel Schneider" iconPath = iconLookup("user-trash-full") def handleQuery(query): if query.string.strip() and "trash".startswith(query.string.lower()): pattern = re.compile(query.string, re.IGNORECASE) return Item(id="trash-open", icon=iconPath, text=pattern.sub(lambda m: "<u>%s</u>" % m.group(0), "Trash"), subtext="Show trash folder", completion="trash", actions=[UrlAction("Show", "trash:///")])
__version__ = "0.1" __trigger__ = "xkcd" __author__ = "Nikos Koukis" __dependencies__ = [] __homepage__ = "https://github.com/bergercookie/xkcd-albert-plugin" # TODO pyproject toml file # TODO xkcd-dl executable? # TODO Upload to github - change support url on error # TODO Send to albert plugins if not which("xkcd-dl"): raise RuntimeError("xkcd-dl not in $PATH - Please install it via pip3 first.") iconPath = v0.iconLookup("xkcd") if not iconPath: iconPath = os.path.join(os.path.dirname(__file__), "image.png") SETTINGS_PATH = Path(v0.cacheLocation()) / "xkcd" LAST_UPDATE_PATH = SETTINGS_PATH / "last_update" XKCD_DICT = Path.home() / ".xkcd_dict.json" def initialize(): # Called when the extension is loaded (ticked in the settings) - blocking # create cache location SETTINGS_PATH.mkdir(parents=False, exist_ok=True) if not LAST_UPDATE_PATH.is_file(): update_date_file() update_xkcd_db()
Password lookup with Lastpass """ import json import subprocess from albertv0 import Item, iconLookup, ClipAction __iid__ = "PythonInterface/v0.1" __prettyname__ = "LastPass" __version__ = "0.1" __trigger__ = "pass " __author__ = "Reetobrata Chatterjee" __dependencies__ = ["lastpass-cli"] lastpass = iconLookup("lastpass") class Entry: def __init__(self, d): self.name = d["name"] self.username = d["username"] self.password = d["password"] @property def ident(self): return " ".join((self.name, self.username)) def matches(self, query): i = 0 j = 0