示例#1
0
def last_slide(m):
    applescript.run(r'''
tell application "Keynote"
	set target to last item of (get slides of the front document)
	set current slide of the front document to target
end tell
''')
示例#2
0
def open_server(m):
    applescript.run(r'''
    tell application "System Events"
        do shell script "python -S ~/dbg/py3_dbgp -d localhost:9000 ~/taest.py"
        display notification "Hello world."
    end tell
    ''')
示例#3
0
def open_dragonpad():
    open_dragon_menubar()
    applescript.run("""
        tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
            click menu item "Help" of menu 1
            click menu item "DragonPad" of menu of menu item "Help" of menu 1
        end tell
    """)
示例#4
0
    def _kmaestro(*_):
        print("Kmaestro {}".format(script_id))

        applescript.run("""
        tell application "Keyboard Maestro Engine"
            do script "{id}"
        end tell
        """.format(id=script_id))
示例#5
0
def set_status_win(val):
    open_dragon_menubar()
    command = "Show Status Window" if val else "Hide Status Window"
    applescript.run(f"""
    tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
        click menu item "{command}" of menu 1
    end tell
    """)
示例#6
0
 def website(m):
     w = url
     code = r'''
     tell application "Google Chrome"
     set t to active tab of window 1
     set URL of t to "%s"
     end tell
     ''' % w
     applescript.run(code)
示例#7
0
def select_menu_bar_item(m):
    name = str(m._words[1])
    full = menu_items.get(name)
    if not full:
        return
    applescript.run(r"""
tell application "System Events"
  tell (first process whose frontmost is true)
    click menu bar item "%s" of menu bar 1
  end tell
end tell
    """ % full)
示例#8
0
def open_website(m):
    name = str(m._words[1])
    w = websites.get(name)
    code = r'''
    tell application "Google Chrome"
	if title of active tab of window 1 is "New Tab" then
            set t to active tab of window 1
	else
            set t to make new tab at end of tabs of window 1
	end if
	set URL of t to "%s"
    end tell
    ''' % w
    applescript.run(code)
示例#9
0
def update_lists():
    global menu_items
    items = applescript.run(r"""
on menubar_items()
    tell application "System Events"
        tell (first process whose frontmost is true)
            tell menu bar 1
                set test to name of every menu bar item
                return test
            end tell
        end tell
    end tell
end menubar_items

set theList to menubar_items()
set {text item delimiters, TID} to {",", text item delimiters}
set {text item delimiters, theListAsString} to {TID, theList as text}
return theListAsString
""")
    if items is not None:
        items = items.split(",")
    else:
        items = []
    new = {}
    for item in items:
        words = item.split(" ")
        for word in words:
            if word and not word in new:
                new[word] = item
        new[item] = item
    if set(new.keys()) == set(menu_items.keys()):
        return
    ctx.set_list("menu_items", new.keys())
    menu_items = new
示例#10
0
def copy_path_to_clipboard(m):
    x = applescript.run("""
    tell application "Finder"
        set sel to the selection as text
        set the clipboard to POSIX path of sel
    end tell
    """)
示例#11
0
def current_dir():
    return applescript.run("""
        tell application "iTerm"
            tell current session of current window
                variable named "session.path"
            end tell
        end tell
        """)
示例#12
0
def open_dragon_pad(m):
    old = ctrl.mouse_pos()
    x = applescript.run("""
    tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
        set AppleScript's text item delimiters to ", "
        position as string
    end tell
    """)
    x, y = map(int, x.split(", "))
    ctrl.mouse(x, y)
    ctrl.mouse_click()
    ctrl.mouse(*old)
    applescript.run("""
    tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
        click menu item "Help" of menu 1
        click menu item "DragonPad" of menu of menu item "Help" of menu 1
    end tell
    """)
示例#13
0
def running_screensaver():
    return (
        applescript.run(
            """
            tell application "System Events"
            get running of screen saver preferences
            end tell
            """
        )
        == "true"
    )
示例#14
0
    def file_manager_terminal_here():
        """Opens terminal at current location"""
        if not is_terminal:
            if is_windows:
                actions.key("ctrl-l")
                actions.insert("cmd.exe")
                actions.key("enter")
            elif is_mac:
                from talon import applescript

                applescript.run(r"""
                tell application "Finder"
                    set myWin to window 1
                    set thePath to (quoted form of POSIX path of (target of myWin as alias))
                    tell application "Terminal"
                        activate
                        tell window 1
                            do script "cd " & thePath
                        end tell
                    end tell
                end tell""")
示例#15
0
def jump_slide(m):
    words = m.dgndictation[0]._words
    numbers = list(map(parse_word, words))
    numbers_map = {
        'zero': '0',
        'one': '1',
        'two': '2',
        'three': '3',
        'for': '4',
        'four': '4',
        'five': '5',
        'six': '6',
        'seven': '7',
        'eight': '8',
        'nine': '9',
    }
    numbers = [numbers_map[n] for n in numbers]
    number = ''.join(numbers)
    applescript.run(r'''
tell application "Keynote"
	set target to item %s of (get slides of the front document)
	set current slide of the front document to target
end tell''' % number)
示例#16
0
def update_lists():
    global menu_items
    items = applescript.run(update_lists_applescript)
    if items is not None:
        items = items.split(",")
    else:
        items = []
    new = {}
    for item in items:
        words = item.split(" ")
        for word in words:
            if word and word not in new:
                new[word] = item
        new[item] = item
    if set(new.keys()) == set(menu_items.keys()):
        return
    ctx.set_list("menu_items", new.keys())
    menu_items = new
示例#17
0
def tell_alfred_flow(workflow, trigger, arg=None):
    argument = f' with argument "{arg}"' if arg != None else ""
        
    script = f'''
    tell application "Alfred 4" to run trigger "{trigger}" in workflow "{workflow}"{argument}'''
    # print(script)
    try:
        ret = applescript.run(script)
    except applescript.ApplescriptErr:
        print('alfred osa error:', script)
        raise
    if ret:
        if isinstance(ret, str) and luaDict[ret]:
            return luaDict[ret]
        
        print('alfred osa returned: ', ret)
        result = ffi.string(ret).decode('utf8')
        # print('osa said: ', result)
        return result
示例#18
0
def tell_hammerspoon_osa(code):
    script = f'''
    tell application "Hammerspoon"
        return execute lua code "{code}"
    end tell'''
    # print(script)
    try:
        ret = applescript.run(script)
    except applescript.ApplescriptErr:
        print('osa error:', script)
        raise
    if ret:
        if isinstance(ret, str) and luaDict[ret]:
            return luaDict[ret]

        print(script)
        print('osa returned: ', ret)
        result = ffi.string(ret).decode('utf8')
        return result
示例#19
0
def youtube_download(video=True):
    press("escape")
    press("cmd-l")
    press("cmd-c")
    time.sleep(0.1)
    url = clip.get()
    print(f"url: {url}")
    press("escape")

    command = f"youtube-dl "
    if not video:
        command += "--extract-audio "
    command += "{url}"
    print(f"command: {command}")

    return applescript.run(f"""
        tell application "Terminal"
            do script "cd {os.path.expanduser(DOWNLOAD_PATH)}; {command}; exit"
        end tell
        """)
示例#20
0
def youtube_download(video=True):
    press('escape')
    press('cmd-l')
    press('cmd-c')
    time.sleep(0.1)
    url = clip.get()
    print(f'url: {url}')
    press('escape')

    command = f'youtube-dl '
    if not video:
        command += '--extract-audio '
    command += '{url}'
    print(f'command: {command}')

    return applescript.run(f"""
        tell application "Terminal"
            do script "cd /Users/zdwiel/Music; {command}; exit"
        end tell
        """)
示例#21
0
def get_input_volume() -> int:
    return int(applescript.run("input volume of (get volume settings)"))
示例#22
0
                                   delay(0.1), text],
    "(kapeli | Cappelli)":
    Key("cmd-shift-space"),
    # Menubar:
    "menubar":
    Key("ctrl-f2"),
    "menubar <dgndictation> [over]": [Key("cmd+shift+/"),
                                      delay(0.1), text],
    "menu icons":
    Key("ctrl-f8"),
    # Bartender needed for this one
    "menu search":
    Key("ctrl-shift-f8"),
    # Different input volume levels
    "input volume high":
    lambda _: applescript.run("set volume input volume 90"),
    "input volume low":
    lambda _: applescript.run("set volume input volume 50"),
})

ctx = Context("shortcat")
ctx.keymap({
    "(shortcat | short cap | shortcut) [<dgndictation>]": [
        Key("cmd+shift+ctrl+f14"),
        text,
    ]
})

ctx = Context("login", bundle="com.apple.loginwindow")
ctx.keymap({"amigo": [keychain.find("login", "user"), Key("enter")]})
示例#23
0
 def applescript(script: str) -> str:
     """Run applescript"""
     return applescript.run(script)
示例#24
0
 def cmd(self, cmd):
     ret = applescript.run(f'tell application "VLC"\n{cmd}\nend tell')
     if ret:
         return ffi.string(ret).decode('utf8')
示例#25
0
 def _spotify(*_):
     applescript.run(f'tell application "Spotify" to {thing}')
示例#26
0
def alfred_paste_num(num):
    script = f'tell application id "com.runningwithcrayons.Alfred" to run trigger "paste" in workflow "clippastes" with argument "{num}"'
    # print(script)
    ret = applescript.run(script)
    if ret:
        return ffi.string(ret).decode('utf8')
示例#27
0
def set_input_volume(m: int):
    applescript.run(f"set volume input volume {m}")
示例#28
0
def run_script(script):
    applescript.run(script)
示例#29
0
def select_menu_bar_item(m):
    name = str(m._words[1])
    full = menu_items.get(name)
    if not full:
        return
    applescript.run(select_menu_bar_item_applescript % full)