Exemple #1
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()
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()
#!/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()
Exemple #4
0
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,
                       'Open MD Note',
                       icon_path='icons/markdown.png',
                       icon_type='image')
            alf.addMod('alt',
                       url,
                       "Copy URL to Clipboard",
                       icon_path='icons/clipboard.png',
                       icon_type='image')
            alf.addItem()
else:
    alf.setItem(title='No Bookmarks found...',
                subtitle='try again',
Exemple #5
0
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',
            icon_type='image'
        )
        wf.addItem()
else:
    wf.setItem(
        title="No Tags found!",
        subtitle="No Tags matches search term",
# 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)",
        type='file',
        arg=f['path'])
    # Mod for CMD - new action menu
    wf.addMod(key="cmd",
              arg=f"{f['path']}>{query}",
              subtitle="Enter Actions Menu for the Note...",
              icon_path="icons/action.png",
              icon_type="image")
    wf.addItem()

if len(wf.getItems(response_type="dict")['items']) == 0:
    wf.setItem(
        title="Nothing found...",
        subtitle=f'Do you want to create a new note with title "{query}"?',
        arg=query)
Exemple #7
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()
Exemple #8
0
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"
            wf.setItem(title=f"{v[0]}",
                       subtitle=f"{v[1].upper()}, Press \u23CE to {arg}",
                       arg=f"{arg};{v[0]}")
            wf.setIcon(m_path=f"{v[1]}.png", m_type="image)")
            wf.addItem()
else:
    wf.setItem(
        title="No VPN configuration found",
        subtitle=
        "Please configure VPN connection in System Preferences → Network",
        valid=False)
    wf.addItem()

if wf.getItemsLengths == 0:
    wf.setItem(title=f'No VPN connection matches "{query}"',
               subtitle="Try again",
               valid=False)
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)
        bookmarks = get_all_urls(bm_json)
        matches = match(query, bookmarks)
        for m in matches:
            name = m[0]
            url = m[1]
            wf.setItem(title=name, subtitle=url, arg=url, quicklookurl=url)
            wf.addItem()

if wf.getItemsLengths() == 0:
    wf.setItem(title='No Bookmark found!',
        # Quicklook file URL
        quicklook_url = create_hint_file(wf_path, content)
        ip = wf_path + "/icon.png"
        # use default icon in alf WF directory in case searched wf has not icon defined
        icon_path = ip if os.path.isfile(ip) else 'icon.png'
        keyword_text = kf.get_keywords_scriptfilter()
        valid = kf.has_keywords()
        subtitle = description + \
            u', Keywords: ' + \
            keyword_text if valid else description
        if len(kf.get_keyboard_shortcuts()) > 0:
            subtitle += ", Keyboard: " + ",".join(kf.get_keyboard_shortcuts())
        arg = os.path.dirname(info_plist_path) + "|" + name
        alf.setItem(title=name,
                    subtitle=subtitle,
                    arg=arg,
                    automcomplete=name,
                    valid=valid,
                    quicklookurl=quicklook_url)
        alf.setIcon(icon_path, m_type="image")
        alf.addMod('cmd',
                   subtitle='Choose Action...',
                   arg=arg,
                   icon_path='icons/start.png',
                   icon_type='image',
                   valid=True)
        alf.addItem()
else:
    alf.setItem(title='No Workflow matches the search query!',
                subtitle=f"...for query: \"{query}\"",
                valid=False)
    alf.addItem()
Exemple #11
0
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')
        wf.addItem()
        wf.setItem(
            title="Preview affected MD Notes",
            subtitle=
            f"Preview of affected md notes. {K.SHIFT} for Quicklook, {K.ENTER} to open. NOTES ARE NOT DELETED!",
            type='file',
            arg=summary_file)
        wf.setIcon(m_path='icons/clipboard.png', m_type='image')
        wf.addItem()
    else:
        wf.setItem(title=f"MD notes not found with tag: {query}",
                   subtitle="Try another tag name",
# 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",
            arg=f"{i['path']}>{query}",
            subtitle="Actions..",
            icon_path="icons/action.png",
            icon_type="image"
        )
        wf.addItem()
else:
    wf.setItem(
Exemple #13
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()
Exemple #14
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()