Beispiel #1
0
def helpMenuMouse():
	scpt = AppleScript('''
		tell application (path to frontmost application as text)
			display dialog "Possible motions:\nWhile Holding Touch: Tilt up/down for dashboard commands.\nTilt left/right to switch applications.\nWithout touch: move to mouse around! Tap/double tap to click/double-click."
		end tell
	''')
	scpt.run()
Beispiel #2
0
def helpMenuChrome():
	scpt = AppleScript('''
		tell application (path to frontmost application as text)
			display dialog "Possible motions:\nTilt, Shake, Move, Tap"
		end tell
	''')
	scpt.run()
Beispiel #3
0
def minimize2():
	scpt = AppleScript('''
		tell application "System Events" to tell (process 1 where frontmost is true)
		    click menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1
		end tell
	''')
	scpt.run()
Beispiel #4
0
def clickTopButton(buttonNum):
	scpt = AppleScript('''
		tell application "System Events" to tell (process 1 where frontmost is true)
		    click button ''' +  str(buttonNum) + ''' of window 1
		end tell
	''')
	scpt.run()
Beispiel #5
0
def keyDownCommand():
	scpt = AppleScript('''
		tell application "System Events"
			key down command
		end tell
	''')
	scpt.run()
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
            'cluster',
            help='the cluster to connect to.')
    parser.add_argument(
            '-c', '--config', default=DEFAULT_CONFIG,
            help='the config file to use (default "%s").' % DEFAULT_CONFIG)
    parser.add_argument(
           '-v', '--verbose', action='store_true', default=False,
            help='increases log verbosity.')
    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    config = Config(path=args.config).cluster(args.cluster)
    logging.debug('Cluster config: %s', config)

    layout = Layout(config)
    logging.debug('Layout: %s', layout)

    window = Window(config)
    logging.debug('Window: %s', window)

    applescript = AppleScript(config, layout, window)
    applescript.launch()
Beispiel #7
0
def volumeDown():
	scpt = AppleScript('''				
		set volOutput to output volume of (get volume settings)
	    set volume output volume (volOutput - 6.25)
	''')
	scpt.run()
	playVolumeSound()
Beispiel #8
0
def helpMenuEarth():
	scpt = AppleScript('''
		tell application (path to frontmost application as text)
			display dialog "Possible motions:\nWhile Holding Touch: Tilt to move around, move vertically to zoom."
		end tell
	''')
	scpt.run()
Beispiel #9
0
def shuffle():
	scpt = AppleScript('''
		tell application "System Events" 
			perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Shuffle")
		end tell
	''')
	scpt.run()
	playSoundEffect('Purr')
Beispiel #10
0
def prevApplication():
	scpt = AppleScript('''
		tell application "System Events"
			keystroke tab using {shift down}
		end tell
	''')
	scpt.run()
	playSoundEffect('Pop')
Beispiel #11
0
def nextApplication():
	scpt = AppleScript('''
		tell application "System Events"
			keystroke tab
		end tell
	''')
	scpt.run()
	playSoundEffect('Pop')
def send_messages(sending_list, text_message):
    r = Tk()
    r.withdraw()
    for receiver in sending_list:
        phone_number, *fields = receiver
        formatted_message = text_message.format(*fields)

        r.clipboard_clear()
        r.clipboard_append(formatted_message)
        r.update()
        applescript = AppleScript(source=APPLE_SCRIPT_UI)
        applescript.run(formatted_message, phone_number)
Beispiel #13
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument(
            'cluster', nargs='?',
            help='the cluster to connect to.')
    parser.add_argument(
            '-c', '--config', default=DEFAULT_CONFIG,
            help='the config file to use (default "%s").' % DEFAULT_CONFIG)
    parser.add_argument(
           '-v', '--verbose', action='store_true', default=False,
            help='increases log verbosity.')
    parser.add_argument(
            '-l', '--list', action='store_true', default=False,
            help='list the clusters in the config file.')
    args = parser.parse_args()

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    config = Config(path=args.config)

    if args.list:
        print "Clusters in %s:" % (args.config)
        for name in config.clusternames():
            print "- %s" % (name)
        return

    # need to check if this is set manually due to use of nargs=? above, which
    # seems to be only way to get an optional arg list --list to work and not
    # also require the cluster positional arg to be set
    if args.cluster is None:
        parser.error("cluster name is required")

    config = config.cluster(args.cluster)
    logging.debug('Cluster config: %s', config)

    layout = Layout(config)
    logging.debug('Layout: %s', layout)

    window = Window(config)
    logging.debug('Window: %s', window)

    applescript = AppleScript(config, layout, window)
    applescript.launch()
Beispiel #14
0
def runSpotifyCommand(command):
    try:
        if command not in commands:
            commands[command] = AppleScript(
                source="tell application \"Spotify\" to " + command)

        return str(commands[command].run()).strip()
    except:
        return "0"
def open_photos_library(photoslibrary, delay=10):
    """ open a Photos library """
    photoslibrary = str(photoslibrary)
    script = AppleScript(f"""
            set tries to 0
            repeat while tries < 5
                try
                    tell application "Photos"
                        activate
                        delay 3 
                        open POSIX file "{photoslibrary}"
                        delay {delay}
                    end tell
                    set tries to 5
                on error
                    set tries to tries + 1
                end try
            end repeat
        """)
    script.run()
Beispiel #16
0
def check_status():
    while True:
        if end.is_set():
            break
        sleep(1)
        s = AppleScript("""tell application "Spotify"
        	return player state
        end tell""")
        try:
            result = s.run()
        except ScriptError:
            continue
        if result.code == b'kPSP':
            playing.set()
        else:
            playing.clear()
        d = Quartz.CGSessionCopyCurrentDictionary()
        if 'CGSSessionScreenIsLocked' in d and d[
                'CGSSessionScreenIsLocked'] == 1:
            sleeping.set()
        else:
            sleeping.clear()
Beispiel #17
0
def run(app: str, qry: str) -> Any:
    """Tells a given application to perform a specific action

    Arguments:
        app {str} -- Application ID of the app to control
        qry {str} -- The action to perform within the given app

    Returns:
        The output of the given action
    """
    script = f'tell application id "{app}" to {qry}'
    try:
        return AppleScript(script).run()
    except ScriptError as error:
        print(error)
        return None
Beispiel #18
0
    def get_track(self) -> Optional[Track]:
        """Return the currently playing track within the given Player.

        Returns:
            Optional[Track] -- The currently playing track for the given Player
        """
        try:
            track_query = 'name of current track'
            artist_query = 'artist of current track'
            album_query = 'album of current track'

            if self.app == PlayerApp.Vox:
                # Vox uses a different syntax for track and artist names
                track_query = 'track'
                artist_query = 'artist'
                album_query = 'album'

            script = f'''
                tell application id "{self.app.value}"
                    set trackname to {track_query}
                    set trackartist to {artist_query}
                    set trackalbum to {album_query}
                    set trackposition to player position
                    set tracklength to duration of current track
                    return {{trackname, trackartist, trackalbum, trackposition, tracklength}}
                end tell
            '''

            results = list(
                map(lambda x: x if x != kMissingValue else '',
                    AppleScript(script).run()))

            return Track(title=results[0],
                         artist=results[1],
                         album=results[2],
                         position=int(results[3]),
                         duration=int(results[4]))
        except ScriptError as error:
            print('error: ', error)
            return None
Beispiel #19
0
PAUSED = 1
PLAYING = 2

track = "N/A"
artist = "N/A"
album = "N/A"
length = 1
pos = 1
status = STOPPED
repeat = False
shuffle = False
volume = 0

commands = {}
prevCommand = AppleScript(
    source=
    "tell application \"Spotify\"\n set player position to 0\n previous track\n end tell"
)


def runSpotifyCommand(command):
    try:
        if command not in commands:
            commands[command] = AppleScript(
                source="tell application \"Spotify\" to " + command)

        return str(commands[command].run()).strip()
    except:
        return "0"


def getTrack():
Beispiel #20
0
import textwrap
from subprocess import check_call

import click
import pasteboard
from applescript import AppleScript, ScriptError, AEType

_GET_FRONT_APP_SCRIPT = AppleScript(
    textwrap.dedent("""\
    tell application "System Events"
        set frontmostApplicationName to name of 1st process whose frontmost is true
    end tell
    return frontmostApplicationName
"""))

_SET_FRONT_APP_SCRIPT = AppleScript(
    textwrap.dedent("""\
    on run {frontmostApplicationName}
        tell application frontmostApplicationName to activate
    end run
"""))
#         display dialog dialogText buttons {"Open", "Edit", "Copy"} default button "Copy" cancel button "Edit" with icon file ((path to application "Iterm2" as text) & "Contents:Resources:AppIcon.icns")
_SHOW_DIALOG_SCRIPT = AppleScript(
    textwrap.dedent("""\
    on run {dialogText}
        activate
        display alert dialogText message "Enter: Copy, Esc: Edit, Space: Open" as informational buttons {"Open", "Edit", "Copy"} default button "Copy" cancel button "Edit" giving up after 30
    end run
"""))

_EVENT_BUTTON_HIT = AEType(b'bhit')
Beispiel #21
0
 def update_task(task, status, flag, dueDate, note, project):
     AppleScript(UPDATE_SCRIPT(task, status, flag, dueDate, note, project)).run()
Beispiel #22
0
 def get_tasks():
     AppleScript(GET_SCRIPT(PERSPECTIVE, OMNI_FOLDER, TASK_FILENAME)).run()
Beispiel #23
0
 def finish_task(task, status, note, project):
     AppleScript(FINISH_SCRIPT(task, status, note, project)).run()
Beispiel #24
0
def windowCommand(keycode):
	scpt = AppleScript('tell application "System Events" to key code ' + str(keycode))
	scpt.run()
Beispiel #25
0
def currApp():
	scpt = AppleScript('''
		return (info for (path to frontmost application))
	''')
	dict = scpt.run()
	return dict[AEType('dnam')]
Beispiel #26
0
def overlay():
	scpt = AppleScript('''				
		display notification "HI SCOTT"
	''')
	scpt.run()
Beispiel #27
0
def tellItunes(value):
	scpt = AppleScript('''
	    tell application "iTunes" to ''' + value
	)
	scpt.run()
Beispiel #28
0
def delay():
	scpt = AppleScript('''
		delay 1
	''')
	scpt.run()
Beispiel #29
0
def typeIntoConsole(string):
	getInConsole()
	scpt = AppleScript('tell application "System Events" to keystroke "' + string + '"')
	scpt2 = AppleScript('tell application "System Events" to keystroke return')
	scpt.run()
	scpt2.run()
Beispiel #30
0
def get_itunes_art(app: str):
    res = None

    script_first = f'''
try
     tell application "{app}"
         tell artwork 1 of current track
             if format is JPEG picture then
                 set imgFormat to ".jpg"
             else
                 set imgFormat to ".png"
             end if
         end tell
         set albumName to album of current track
         set albumArtist to album artist of current track
         if length of albumArtist is 0
             set albumArtist to artist of current track
         end if
         set fileName to (do shell script "echo " & quoted form of albumArtist & quoted form of albumName & " | sed \\"s/[^a-zA-Z0-9]/_/g\\"") & imgFormat
     end tell
     do shell script "echo " & (POSIX path of (path to temporary items from user domain)) & fileName
 on error errText
     ""
 end try'''

    script_second = f'''
try
    tell application "{app}"
        tell artwork 1 of current track
            set srcBytes to raw data
            if format is JPEG picture then
                set imgFormat to ".jpg"
            else
                set imgFormat to ".png"
            end if
        end tell
        set albumName to album of current track
        set albumArtist to album artist of current track
        if length of albumArtist is 0
            set albumArtist to artist of current track
        end if
        set fileName to (do shell script "echo " & quoted form of albumArtist & quoted form of albumName & " | sed \\"s/[^a-zA-Z0-9]/_/g\\"") & imgFormat
    end tell
    set tmpName to ((path to temporary items from user domain) as text) & fileName
    set outFile to open for access file tmpName with write permission
    set eof outFile to 0
    write srcBytes to outFile
    close access outFile
    tell application "Image Events"
        set resImg to open tmpName
        scale resImg to size 300
        save resImg
        close resImg
    end tell
    do shell script "echo " & (POSIX path of (tmpName))
on error errText
    ""
end try'''

    try:
        res = AppleScript(script_first).run()
    except ScriptError:
        pass

    if res and not os.path.isfile(res):
        try:
            res = AppleScript(script_second).run()
        except ScriptError:
            pass

    return res
Beispiel #31
0
import os
from typing import Any

from applescript import AppleScript, ScriptError

apps_exist = AppleScript('''
    on run {appList}
        repeat with a from 1 to length of appList
            set appname to item a of appList
            try
                tell application "Finder" to get application file id appname
                set item a of appList to true
            on error
                set item a of appList to false
            end try
        end repeat

        return appList
    end run
''')

apps_running = AppleScript('''
    on run {appList}
        repeat with a from 1 to length of appList
            set appname to item a of appList
            set item a of appList to (application id appname is running)
        end repeat

        return appList
    end run
''')
Beispiel #32
0
def mute():
	scpt = AppleScript('''				
		set isMuted to output muted of (get volume settings)
	    set volume output muted (not isMuted)
	''')
	scpt.run()