Example #1
0
def get(location):
    ''' Open the location '''
    
    if location:
        message = "Opening it."
        paul.run_script('open "{}"'.format(location))
        return message.format(location)
    else:
         return "I couldn't find anything."
Example #2
0
def reveal(location):
    ''' Show the location in the Finder '''
    
    if location:
        message = "I found something..."
        paul.run_script('tell application "Finder" to '
                        'reveal POSIX file "{}"'.format(location), 
                        language="applescript")
        return message.format(location)
    else:
         return "I couldn't find anything."
Example #3
0
def show_all(query):
    ''' Open the finder with a search done '''
    script = ('tell application "Finder" to activate\n'
    + 'tell application "System Events"\n'
    + '\tkeystroke "n" using {command down}\n'
    + '\tkeystroke "f" using {command down}\n'
    + '\tkey code 48 using {control down, shift down}\n'
    + '\tkeystroke "w" using {command down}\n'
    + '\tkeystroke "' + query + '"\n'
    + '\tkey code 36\nend tell')
    paul.run_script(script, language='applescript')
    return "Here, try these..."
Example #4
0
def repeat():
    """ Repeat the last action that was done, if it is still stored in "it".
        No argument. Return a string as a response. """
    it = paul.get_it()
    if it.startswith('tell application "System Events" to key code'):
        paul.run_script(it, language="applescript")
        return "Ok."
    elif it.startswith("set volume output volume (output volume of "):
        paul.run_script(it, language="applescript")
        return "Ok."
    else:
        return "What? I don't understand."
Example #5
0
def change_volume(keywords):
    """ Change the volume up or down, depending on the keywords """

    code = "set volume output volume (output volume of (get volume settings) {} 6.25)"
    if paul.has_one_of(keywords, VERBS_UP + ["turn up", "adjust up", "louder"]):
        code = code.format("+")
    elif paul.has_one_of(keywords, VERBS_DOWN + ["turn down", "adjust down", "quieter"]):
        code = code.format("-")
    else:
        return "I'm not sure how you wanted me adjust the volume."
    paul.set_it(code)
    paul.run_script(code, language="applescript")
    return "Done!"
Example #6
0
def change_brightness(keywords):
    """ Change the brightness up or down, depending on the keywords """
    code = 'tell application "System Events" to key code {}'
    up = "113"
    down = "107"

    if paul.has_one_of(keywords, VERBS_UP + ["turn up", "adjust up", "brighter"]):
        code = code.format(up)
    elif paul.has_one_of(keywords, VERBS_DOWN + ["turn down", "adjust down", "dimmer"]):
        code = code.format(down)
    else:
        return "I can't tell how you wanted the brightness changed."
    paul.set_it(code)
    paul.run_script(code, language="applescript")
    return "Done!"
Example #7
0
def find(params="", look_in=False):
    ''' Find the item that was searched for with necessary paramenters '''
    
    home = look_in if look_in else "~"
    
    avoiders = [
        "Library",
        "Cache",
        ".log",
        ".properties",
    ]
    
    command = 'mdfind -onlyin {}/ "{}"'.format(home.strip("\n"), params)
    
    results = paul.run_script(command, response=True).split("\n")[:-1]
    filtered_results = sorted([line.strip() for line in results 
                    if not has_one_of_substrings(line.strip(), avoiders)], key=len)
    paul.log("RESULTS FIRST 5: ", filtered_results[:10])
    
    if len(filtered_results) > 0:
        if len(filtered_results) > 1:
            decision = choose(filtered_results[:5])
        else:
            decision = filtered_results[0]
        paul.log("DECISION: " + str(decision))
        it = paul.set_it(decision)
        paul.log('IT: {}'.format(it))
        return decision
    else:
        return None
Example #8
0
    "mute",
    "louder",
    "quieter",
    "brighter",
    "dimmer",
    "silent",
    "silence",
]

VERBS_UP = ["increase", "raise", "up"]

VERBS_DOWN = ["decrease", "lower", "down"]

NOUNS = ["volume", "screen", "system", "computer", "brightness", "screensaver", "desktop"]

screensaver = lambda: paul.run_script('tell application "ScreenSaverEngine" to activate', language="applescript")

sleep = lambda: paul.run_script('tell application "Finder" to sleep', language="applescript")

desktop = lambda: paul.run_script('tell application "System Events" to key code 103', language="applescript")

mute = lambda: paul.run_script(
    "set toggle to get volume settings\n"
    + "if output muted of toggle is false then\n"
    + "    set volume with output muted\n"
    + "else\n"
    + "    set volume without output muted\n"
    + "end if",
    language="applescript",
)