Пример #1
0
        value (str): value of key-value pair
    """
    config = Plist()
    config.setVariable(key, value)
    value = '<EMPTY>' if value == str() else value
    wf.setItem(title="Proceed?",
               subtitle=f'{key} will be changed to: {value}',
               arg='')
    wf.setIcon('icons/hand.png', 'image')
    wf.addItem()


query = Tools.getArgv(1)
action_key_value = Tools.getEnv('action_key_value')
[action, key,
 value] = action_key_value.split('|') if action_key_value != str() else [
     str(), str(), str()
 ]
wf_dir = os.getcwd()
query = Tools.getArgv(1)

wf = Items()

if action == str():
    print_config(query)
elif action == 'selection':
    get_selection(key, query)
else:
    write_config(key, value)
wf.write()
Пример #2
0
#!/usr/bin/python3

import os

from Alfred3 import Items, Tools

# Script Filter icon [Title,Subtitle,arg/uid/icon]
wf_items = [
    ['Open Workflow', 'Open Workflow in Alfred Preferences', 'open'],
    ['Path to Clipboard', 'Copy Workflow path to Clipoard', 'clipboard'],
    ['Open in Terminal', 'Open Workflow path in Terminal', 'terminal'],
    ['Finder', 'Reveal in Finder', 'finder'],
]

# Add file manager defined in Alfred wf env
file_manager_path = Tools.getEnv('file_manager')
if file_manager_path and os.path.isfile(file_manager_path):
    app_name = os.path.splitext(os.path.basename(file_manager_path))[0]
    wf_items.append([app_name, f"Reveal in {app_name}", "file_manager"])

wf = Items()
for w in wf_items:
    wf.setItem(title=w[0], subtitle=w[1], arg=w[2])
    icon_path = f'icons/{w[2]}.png'
    wf.setIcon(icon_path, m_type='image')
    wf.addItem()

wf.write()
Пример #3
0
# create MD search object
md = Search()

# Get environment variables
ext = md.getNotesExtension()
query = normalize('NFC', Tools.getArgv(1))  # Tag name

if query is str():
    # Tag Search and sort based on tag name
    tag_results = md.tagSearch(query, 'tag', reverse=False)
else:
    # Tag Search and sort based on number of Hits
    tag_results = md.tagSearch(query, 'count', reverse=True)

wf = Items()

if bool(tag_results):
    for tag, counter in tag_results.items():
        wf.setItem(
            title=f'{tag}',
            subtitle=f"{counter} Hit(s), ({K.CMD} to paste tag into frontmost app)",
            valid=True,
            arg=f'#{tag}'
        )
        wf.setIcon('icons/hashtag.png', 'image')
        wf.addMod(
            key='cmd',
            arg=f'#{tag} ',
            subtitle='Paste Tag into frontmost app',
            icon_path='icons/paste.png',
Пример #4
0
# -*- coding: utf-8 -*-

from Alfred3 import Items, Tools
from MyNotes import Search

query = Tools.getArgv(1)
bmt = Tools.getEnv('bookmark_tag')
bookmark_tag = bmt if bmt.startswith('#') else f'#{bmt}'

search_terms = f'{bookmark_tag}&{query}' if query else bookmark_tag

notes = Search()
search_terms, _ = notes.get_search_config(search_terms)
matches = notes.url_search(search_terms)

alf = Items()
if matches:
    for m in matches:
        note_title = m.get('title')
        note_path = m.get('path')
        links = m.get('links')
        for l in links:
            url_title = l.get('url_title')
            url = l.get('url')
            subtitle = f'NOTE: {note_title} URL: {url[:30]}...'
            alf.setItem(title=url_title,
                        subtitle=subtitle,
                        arg=url,
                        quicklookurl=url)
            alf.addMod('cmd',
                       note_path,
Пример #5
0
        "icon": "icons/marked.png",
        "visible": True
    },
    {
        "title": "Url Scheme",
        "subtitle": "Copy Url Scheme as Markdown Link to Clipboard",
        "arg": f"urlscheme|{note_path}",
        "icon": "icons/scheme.png",
        "visible": Tools.getEnv("url_scheme")
    },
    {
        "title": "Delete Note",
        "subtitle": f'Delete "{note_title}". This action cannot be undone!',
        "arg": f"delete|{note_path}>{query}",
        "icon": "icons/delete.png",
        "visible": True
    },
]

# Generate ScriptFilter Output
wf = Items()
for a in ACTIONS:
    val = a.get('visible')
    if val:
        wf.setItem(title=a.get("title"),
                   subtitle=a.get("subtitle"),
                   arg=a.get("arg"))
        wf.setIcon(m_path=a.get("icon"), m_type="image")
        wf.addItem()
wf.write()
from Alfred3 import Tools as Tools
from MyNotes import Search

CMD = u'\u2318'
SHIFT = u'\u21E7'

# create MD search object
md_search = Search()

query = Tools.getArgv(1)  # Search Term(s)

# Get Search config with AND and OR
search_terms, search_type = md_search.get_search_config(query)

# create WF object
wf = Items()

# exec search if search terms were entered
if len(search_terms) > 0:
    sorted_file_list = md_search.notes_search(search_terms, search_type)
# get full list of file in case no search was entered
else:
    sorted_file_list = md_search.getFilesListSorted()
# Write search results into WF object
for f in sorted_file_list:
    c_date = Tools.getDateStr(f['ctime'])
    m_date = Tools.getDateStr(f['mtime'])
    wf.setItem(
        title=f['title'],
        subtitle=
        f"Created: {c_date}, Modified: {m_date} ({K.CMD} Actions, {K.SHIFT} Quicklook)",
Пример #7
0
def main():
    query = Tools.getArgv(1)
    wf = Items()
    if is_blueutil():
        for ap_name, status in paired_airpods().items():
            adr: str = status.get('address')
            ap_type: str = status.get('prod_label')
            is_connected: bool = status.get('connected')
            con_str: str = "connected, Press \u23CE to disconnect..." if is_connected else "NOT connected, \u23CE to connect..."
            ico: str = f"{ap_type}.png" if is_connected else f"{ap_type}_case.png"
            con_switch: str = "connected" if is_connected else "disconnected"
            if query == "" or query.lower() in ap_name.lower():
                wf.setItem(title=ap_name,
                           subtitle=f"{ap_name} are {con_str}",
                           arg=f"{adr};{con_switch}",
                           uid=adr)
                wf.setIcon(ico, "image")
                wf.addItem()
    else:
        wf.setItem(
            title="BLUEUTIL required!",
            subtitle='Please install with "brew install blueutil" first',
            valid=False)
        wf.addItem()
    wf.write()
Пример #8
0
def add_to_vpnlist(source: list, target: list, status: str) -> list:
    for v in source:
        vpn_tpl = (v, status)
        target.append(vpn_tpl)
    return target


def arrange(lst: list, toarrange: str) -> list:
    for i in lst:
        if i[1] == toarrange:
            lst.remove(i)
            lst.insert(0, i)
    return lst


wf = Items()

query = Tools.getArgv(1)

connected_vpn = get_vpn(status=VPN.CONNECTED)
disconnected_vpn = get_vpn(status=VPN.DISCONNECTED)

vpn = list()
vpn = add_to_vpnlist(connected_vpn, vpn, VPN.CONNECTED)
vpn = add_to_vpnlist(disconnected_vpn, vpn, VPN.DISCONNECTED)

if len(vpn) > 0:
    vpn = arrange(vpn, VPN.CONNECTED)
    for v in vpn:
        if query.lower() in v[0].lower() or query == "":
            arg = f"connect" if v[1] == VPN.DISCONNECTED else f"disconnect"
            result_lst.append(r)
        if search_operator == "|" and any(
            [is_in_tuple(r, ts) for ts in search_terms]):
            result_lst.append(r)
        if search_operator != "|" and search_operator != "&" and any(
            [is_in_tuple(r, ts) for ts in search_terms]):
            result_lst.append(r)
    return result_lst


Tools.log("PYTHON VERSION:", sys.version)
if sys.version_info < (3, 7):
    print('Python version 3.7.0 or higher required!')
    sys.exit(0)

wf = Items()
query = Tools.getArgv(1) if Tools.getArgv(1) is not None else str()
bms = paths_to_bookmarks()
fire_path = path_to_fire_bookmarks()

if fire_path:
    fire_bms = load_fire_bookmarks(fire_path)
    fire_bms = removeDuplicates(fire_bms)
    matches = match(query, fire_bms) if query != str() else fire_bms
    for ft, furl in matches:
        wf.setItem(title=ft, subtitle=furl, arg=furl, quicklook=furl)
        wf.addItem()

if len(bms) > 0:
    for bookmarks_file in bms:
        bm_json = get_json_from_file(bookmarks_file)
def main():
    wf = Items()

    search_term = Tools.getArgv(1)
    locked_history_dbs = history_paths()
    results = list()
    if search_term is not None:
        results = get_histories(locked_history_dbs, search_term)
    else:
        sys.exit(0)
    if len(results) > 0:
        for i in results:
            url = i[0]
            title = i[1]
            visits = i[2]
            wf.setItem(title=title,
                       subtitle=f"(Visits: {visits}) {url}",
                       arg=url,
                       quicklookurl=url)
            wf.addItem()
    if wf.getItemsLengths() == 0:
        wf.setItem(
            title="Nothing found in History!",
            subtitle=f'Search "{search_term}" in Google?',
            arg=f"https://www.google.com/search?q={search_term}",
        )
        wf.addItem()
    wf.write()
Пример #11
0
        [i for i in spath if str(i).startswith('user.workflow')])
    if wf_dir_name != str():
        target_file = f"{target_dir}/{wf_dir_name}.md"
        with open(target_file, "wb+") as f:
            f.write(content)
            return target_file


Tools.logPyVersion()
Workflows = Workflows()
query = Tools.getArgv(1)
matches = Workflows.get_workflows() if query == str(
) else Workflows.search_in_workflows(query)

clean_cache()
alf = Items()
if len(matches) > 0:
    for m in matches:
        # init Keyword and Keyboard text formatter for markdown output
        kf = KeywordFormatter()
        # WF description
        description = m.get('description') if m.get('description') else ' - '
        # WF name
        name = m.get('name')
        # Read WF keyboard shortcuts
        keyb_list = m.get('keyb')
        for k in keyb_list:
            kf.add_keyb(k.get('keyb'))
        # Get list of keywords
        keyword_list = m.get('keywords')
        info_plist_path = m.get('path')
Пример #12
0
    return cache_file_path


# create MD search object
md_search = Search()

# Load Env variables
query = Tools.getArgv(1) if len(Tools.getArgv(1)) > 2 else ""
if query is not "" and not (query.startswith("#")):
    query = f"#{query}"

# Get Search config with AND and OR
search_terms, search_type = md_search.get_search_config(query)

# create WF object
wf = Items()

# exec search if search terms were entered
if len(search_terms) > 0:
    sorted_file_list = md_search.notes_search(search_terms, search_type)
    matches = len(sorted_file_list)
    file_pathes = [f['path'] for f in sorted_file_list]
    arg_string = "|".join(file_pathes)
    summary_file = write_summary(sorted_file_list, query)
    if matches > 0:
        wf.setItem(
            title=f"Batch delete {matches} notes with tag {query}",
            subtitle=
            f"{K.ENTER} to delete ALL notes and corresponding Assets. THIS CANNOT BE UNDONE!",
            arg=arg_string)
        wf.setIcon(m_path='icons/delete.png', m_type='image')
Пример #13
0
import MyNotes
from Alfred3 import Items as Items
from Alfred3 import Keys as K
from Alfred3 import Tools as Tools

# create MD search object
md_search = MyNotes.Search()

# Load environment variables
ext = md_search.getNotesExtension()
query = Tools.getArgv(1)  # Search term

todos = md_search.todoSearch(query)

wf = Items()
if len(todos) > 0:
    for i in todos:
        md_path = pathname2url(i['path'])
        md_title = i['title'] if i['title'] != str() else Tools.chop(i['filename'], ext)
        wf.setItem(
            title=i['todo'],
            subtitle=f"{K.ARROW_RIGHT} {md_title} (Created: {Tools.getDateStr(i['ctime'])}, Modified: {Tools.getDateStr(i['mtime'])})",
            arg=i['path'],
            valid=True,
            type='file'
        )
        wf.setIcon('icons/unchecked.png', 'image')
        # Mod for CMD - new action menu
        wf.addMod(
            key="cmd",
Пример #14
0
	end repeat
end tell

return folder_list
"""


def get_folders(folders_string: str) -> list:
    f = [x.strip("\n") for x in folders_string.split(",")]
    return [x.strip() for x in f]


query = Tools.getArgv(1)

p = Popen(['osascript', '-'],
          stdin=PIPE,
          stdout=PIPE,
          stderr=PIPE,
          universal_newlines=True)
stdout, stderr = p.communicate(scpt)
folders = get_folders(stdout)

wf = Items()

for f in folders:
    if query == "" or query in f:
        wf.setItem(title=f, subtitle=f"Create a note in \"{f}\"", arg=f)
        wf.addItem()

wf.write()
Пример #15
0
SUFFIX = " (DEFAULT)"

# create MD search object
my_notes = MyNotes.Search()

# Load env variables
ext = my_notes.getNotesExtension()
query = Tools.getArgv(1)
default_template = Tools.getEnv('default_template')
template_tag = get_template_tag()

# Get Files sorted in Notes directory
all_files = my_notes.getFilesListSorted()
template_files = sorted(all_files,
                        key=lambda x: x['filename'] != default_template)

wf = Items()
for md_file in template_files:
    if my_notes.isNoteTagged(md_file['path'],
                             template_tag) and query in md_file['filename']:
        suffix = str()
        if md_file['filename'] == default_template:
            suffix = SUFFIX
        wf.setItem(
            title=md_file['filename'] + suffix,
            subtitle=f"Create new file based on \"{md_file['filename']}\"",
            arg=Tools.strJoin(md_file['path']),
            type='file')
        wf.addItem()
wf.write()