Пример #1
0
def get_readkit_info():
    """Activates ReadKit and gets the title and url for the selected post"""
    
    app(u'ReadKit').activate()

    # try first method which is for rss display. 
    # If it is in web display mode this will trigger exception
    
    try:
        # UI element for Title is 3 lines: [blog name, title ,  date]
        title_info= app(u'System Events').application_processes[u'ReadKit'].windows[1].splitter_groups[1].scroll_areas[1].UI_elements[1].UI_elements[1].name.get()
        title = title_info.split('\n')[1]
        
        # click the menu for "Copy Link"
        app(u'System Events').application_processes[u'ReadKit'].menu_bars[1].menu_bar_items[7].menus[1].menu_items[1].click()
    
        sa = OSAX()
        link = sa.the_clipboard()
        
        
    except:
        
        # second method assumes it's a web display which is a lost cause getting out of ReadKit
        # send it to Safari instead
        
        app(u'System Events').keystroke("b")
        app(u'Safari').activate()
        title = app(u'Safari').windows[1].current_tab.name.get() 
        link = app(u'Safari').windows[1].current_tab.URL.get()
        
    return [title, link]
Пример #2
0
def getclipbloard():
    """
    Returns as a string the data on the clipboard
    """

    sa = OSAX()
    return sa.the_clipboard()
 def handle(self):
     # self.request is the TCP socket connected to the client
     # This assumes only one command is sent per TCP connection - Inefficent!
     sa = OSAX()
     self.data = self.request.recv(1024).strip()
     if self.data != "":
         print "{} wrote:".format(self.client_address[0])
         print self.data
         
         # Loosely, designed as I went "protocol"
         if self.data.isdigit():
             d = int(self.data)
             sa.set_volume((d+0.2)/14.2)
             print "set volume to %f" % d
         elif self.data == "PLAY":
             print "Playing iTunes"
             cmd('osascript -e \'tell application "iTunes" to play\'')
         elif self.data == "PAUSE":
             print "Pausing Itunes"
             cmd('osascript -e \'tell application "iTunes" to pause\'')
         elif self.data == "NEXT":
             print "Going to the next track"
             cmd('osascript -e \'tell application "iTunes" to next track\'')
         elif self.data == "PANIC":
             print "Going to the next track"
             cmd('osascript -e \'tell application "iTunes" to pause\'')
             cmd("afplay %s" % PANIC_WAV_FILENAME)
             cmd('osascript -e \'tell application "iTunes" to play\'')
         else:
             print ("UNDEFINED COMMAND", self.data)
Пример #4
0
def main():
    sa = OSAX()
    url = sa.the_clipboard()
    
    print url
    
    post =  getpostnum(url)
    opentreeapp(post)
Пример #5
0
def osx_notify():
    try:
        from osax import OSAX
    except:
        print("appscript not installed ...")

    sa = OSAX()
    sa.activate()
    sa.display_dialog("%s: computations are finished!" % (sys.argv[0]))
Пример #6
0
def shortenSafari():
    Safari = app(u'/Applications/Safari.app')
    url = Safari.windows[1].current_tab.URL.get()

    print url

    short_url = shorten(url)

    sa = OSAX()
    sa.set_the_clipboard_to(short_url)
    print short_url
Пример #7
0
def shortenSafari():
    Safari = app(u'/Applications/Safari.app')
    url = Safari.windows[1].current_tab.URL.get()

    print url

    short_url = shorten(url)

    sa = OSAX()
    sa.set_the_clipboard_to(short_url)
    print short_url
Пример #8
0
def shortenReeder():
    Reeder = app(u'/Applications/Reeder.app')
    Reeder.activate()
    SE = app(u'System Events')
    SE.keystroke('c', using=k.control_down)
    
    sa = OSAX()
    url = sa.the_clipboard()

    print url

    short_url = shorten(url)
    sa.set_the_clipboard_to(short_url)
    
    print short_url
Пример #9
0
def shortenReadKit():
    ReadKit = app(u'/Applications/ReadKit.app')
    ReadKit.activate()
    SE = app(u'System Events')
    SE.keystroke('c', using=[k.command_down,k.option_down])
    time.sleep(1)
    sa = OSAX()
    url = sa.the_clipboard()

    print url

    short_url = shorten(url)
    sa.set_the_clipboard_to(short_url)
    
    print short_url
Пример #10
0
def main(argv=None):

    app(u'/Applications/MarsEdit.app').activate()
    time.sleep(1)
    SE = app(u'System Events')
    SE.keystroke(u'c',using=k.command_down)
    sa = OSAX()
    text = sa.the_clipboard().split('\r')
    out = []
    for l in text:
        out.append(titlecase(l))
    
    out_text = '\r'.join(out)
    sa.set_the_clipboard_to( out_text )
    SE.keystroke(u'v',using=k.command_down)
Пример #11
0
def gettime():
    # by specifying System Events you keep python from
    # creating a GUI app
    
    sa = OSAX("StandardAdditions", name="System Events")
    
    # bring dialog to front
    sa.activate()
    data = sa.display_dialog("Test",buttons=["OK","Cancel"],
                    default_button=1, 
                    default_answer="Event - tomorrow")
    
    if data == None:
        return ""
    
    if data[k.button_returned] == "OK":
        return data[k.text_returned]
    else:
        return ""
Пример #12
0
def run():
    iCal = app(id='com.apple.iCal')

    iCal.activate()
    app(id='com.apple.systemevents').keystroke('c', using=k.command_down)

    eventString = NSPasteboard.generalPasteboard().readObjectsForClasses_options_(
        [NSString], {})[0]

    calendar_names = iCal.calendars[its.writable == True].name.get()

    sa = OSAX(id='com.apple.iCal', terms=standardadditions)
    calendar_name = sa.choose_from_list(calendar_names, with_title='Duplicate',
                                        with_prompt="Copy event to calendar:",
                                        default_items=[calendar_names[0]],
                                        OK_button_name="Duplicate",
                                        multiple_selections_allowed=False,
                                        empty_selection_allowed=False)
    if not calendar_name:
        sys.exit(0)
    calendar_name = calendar_name[0]

    p = {}

    p[k.summary], dates, other = eventString.split('\n', 2)

    date, start, end = re.match(r'scheduled (.+) from (.+) to (.+)',
                                dates).groups()
    p[k.start_date] = parse_date_time(date, start)
    p[k.end_date] = parse_date_time(date, end)

    if other.startswith('Location: '):
        location, p[k.description] = other.split('\n', 1)
        p[k.location] = location.split(': ', 1)[1]
    else:
        p[k.description] = other

    event = iCal.calendars[calendar_name].make(new=k.event, with_properties=p)
    event.make(new=k.sound_alarm, with_properties={
            k.trigger_interval: -10, k.sound_name: 'Basso'})
Пример #13
0
def osx_notify():
    try:
        from osax import OSAX
    except:
        print 'appscript not installed ...'

    sa = OSAX()
    sa.activate()
    sa.display_dialog('%s: computations are finished!' % (sys.argv[0]))
Пример #14
0
def insert_text_cb(text):

    sa = OSAX()

    # save old clipboard (only text part)
    oldtext = sa.the_clipboard()

    # put our text on clipboard
    sa.set_the_clipboard_to(text)

    # paste clipboard
    ME = app(u'System Events').application_processes[u'MarsEdit']
    ME.menu_bars[1].menu_bar_items[4].menus[1].menu_items[6].click()

    # restore old clipboard
    # need to pause so we don't replace clipboard before it is pasted
    time.sleep(.5)

    sa.set_the_clipboard_to(oldtext)
Пример #15
0
def insert_text_cb(text):
    
    sa = OSAX()

    # save old clipboard (only text part)
    oldtext = sa.the_clipboard()
    
    # put our text on clipboard
    sa.set_the_clipboard_to(text)
 
    # paste clipboard
    ME = app(u'System Events').application_processes[u'MarsEdit']
    ME.menu_bars[1].menu_bar_items[4].menus[1].menu_items[6].click()

    # restore old clipboard 
    # need to pause so we don't replace clipboard before it is pasted
    time.sleep(.5)

    sa.set_the_clipboard_to( oldtext )
Пример #16
0
 #!/usr/bin/python
 2  
 3  from appscript import *
 4  from osax import OSAX
 5  
 6  sa = OSAX()
 7  win = app('/Applications/Utilities/Terminal').windows[1]
 8  title = win.name.get().lower()
 9  
10  if title.find("bash") > -1:
11    inout = win.selected_tab.history.get().split('\n$ ')[-2]
12    sa.set_the_clipboard_to('\n'.join(inout.split('\n')[1:-1]))
13  elif title.find("python") > -1 or title.find("matlab") > -1:
14    inout = win.selected_tab.history.get().split('\n>>> ')[-2]
15    sa.set_the_clipboard_to('\n'.join(inout.split('\n... ')[-1].split('\n')[1:]))
Пример #17
0
def setclipboard(text):
    """
    Sets the clipboard to text
    """
    sa = OSAX()
    sa.set_the_clipboard_to(text)
Пример #18
0
#!/usr/bin/python

from appscript import *
from osax import OSAX

session = app('/Applications/iTerm').current_terminal().current_session()

result = session.text().split('\n')[-20:-1]
for index, line in enumerate(result):
    print '  ', index, line[0:100]
line = int(raw_input('Line: '))
sa = OSAX()
sa.set_the_clipboard_to(result[line])
result[line]

Пример #19
0
      if moments['m00']:
        x += int(moments['m10']/moments['m00'])
        y += int(moments['m01']/moments['m00'])
    if len(contours) > 0:
      self.position = (self.cut[0]+x/len(contours), y/len(contours))
    return res

if __name__ == "__main__":
  vc = cv2.VideoCapture(0)
  _, frame = vc.read()

  buddha = Buddha()
  player = Player()
  freq_tool = Tool()
  mul_tool = Tool()
  sa = OSAX()
  
  # Choice of buddha
  cv2.namedWindow("choice")
  while True and not buddha.chosen():
    if frame is not None:
      if not buddha.chosen():
        buddha.detectAndChoose(frame)
        cv2.imshow("choice", frame)
        pressed_key = cv2.waitKey(0) & 0xFF
        if pressed_key >= ord('0') and pressed_key <= ord('9'):
          buddha.choose(pressed_key - ord('0'))
        elif pressed_key == ord('q'):
          sys.exit(0)
    rval, frame = vc.read()
    if cv2.waitKey(1) & 0xFF == ord('q'):
Пример #20
0
    tweets = []

    for status in statuses:
        tweets.append(status.text)

    return tweets


try:
    # Provide Twitter API Credentials
    api = twitter.Api(
        consumer_key=CONSUMER_KEY,
        consumer_secret=CONSUMER_SECRET,
        access_token_key=ACCESS_TOKEN,
        access_token_secret=ACCESS_TOKEN_SECRET,
    )

    # Verify API Credentials
    user = api.VerifyCredentials()
    if user:
        print("Verified API Credentials")

    Notes = extractNotes()
    print("All notes fetched!")
    mac = OSAX()
    mac.say("All notes have been fetched, sir!", using="victoria")


except Exception as e:
    print("Error Occurred : {0}").format(e)
Пример #21
0
    pass

  
def key_stroke(kcode):
  try:
    return scpt.call('doKeyStorke', kcode)
  except applescript.ScriptError:
    return 0
  
def get_brightness():
  try:
    return scpt.call('getBrightness')
  except applescript.ScriptError:
    return 0

sa = OSAX()
scpt = applescript.AppleScript('''
    on doKeyStorke(keycode)
      tell application "System Events" to key code keycode
    end doKeyStorke
    on changeBrightness(BrightnessValue)	
	    tell application "System Preferences"
		    --activate
		    set current pane to pane "com.apple.preference.displays"
    	end tell
    	tell application "System Events" to tell process "System Preferences"		
    		tell slider 1 of group 1 of tab group 1 of window 1 to set value to BrightnessValue
    	end tell
    	tell application "System Preferences" to quit
    end changeBrightness
Пример #22
0
    index += 1

try:
    num = int(raw_input('Enter the number:'))
    if num > 0 and num <= len(availables):
        selected = availables[num - 1]
except Exception as e:
    print "invalid input!"
    exit(1)

try:
    ser = serial.Serial(selected, baud, timeout=timeout)
except Exception as e:
    print "failed to connect the serial port", e

sa = OSAX()
old_brightness = 0
old_volume = 0


def change_brightness(new_val):
    global old_brightness, sa
    if abs(int(new_val) - int(old_brightness)) > 1:
        cmd = "01SBRI%3.0f" % float(new_val)
        ser.write(cmd)
        old_brightness = new_val


def change_volume(new_val):
    global old_volume, sa
    if abs(int(new_val) - int(old_volume)) > 1: