favourite scripts (2)

2,131 views
Skip to first unread message

cedardoc

unread,
Mar 22, 2010, 12:49:50 AM3/22/10
to autokey-users
This closed thread:

http://groups.google.com/group/autokey-users/browse_thread/thread/ed0089c84cb3aa40/3de6e43b7c6b3f50?lnk=gst&q=scripts#3de6e43b7c6b3f50

asked for favourite scripts. Here's one of mine. Its to quickly add
an item to a groceries.txt file:

retCode, gitem = dialog.input_dialog("Add to groceries", "What would
you like to pick up at the grocery store?")
output = system.exec_command("date '+ - %a %b %d '")
gitem2 = "\n" + gitem
fileHandle = open ( '/home/david/Dropbox/groceries.txt', 'a' )
fileHandle.write (gitem2)
fileHandle.write (output)
fileHandle.close()

and I use this to open the file:

keyboard.send_key("<escape>")
import subprocess
subprocess.call(['xdg-open', '/home/david/Dropbox/groceries.txt'])

simple, but effective. :-)

cedardoc

unread,
Mar 28, 2010, 11:30:03 PM3/28/10
to autokey-users
Here's a good one that lets you use google calendar quick add to make
an appointment in your appointment book without having to open your
calendar or even your browser directly. It uses the google calendar
API found here:

http://code.google.com/apis/calendar/data/1.0/developers_guide_python.html#CreatingQuickAdd

You have to download the Python client library, then put this into a
script (just change the username and password)

retCode, date = dialog.calendar(title="Choose a date", format="%Y-%m-
%d", date="today")
#retCode, seedate = dialog.input_dialog(title="here's the date",
message="", default=(getdate))
retCode, time = dialog.input_dialog("what time?", "starting at what
time?")
retCode, event1 = dialog.input_dialog("the event?", "what's the
event?")
event2 = event1 + " " + date + " " + time
#retCode, seedate = dialog.input_dialog(title="here's the event",
message="", default=(event2))

#everything from here down is from:
#http://code.google.com/apis/calendar/data/1.0/
developers_guide_python.html#CreatingQuickAdd

try:
from xml.etree import ElementTree # for Python 2.5 users
except ImportError:
from elementtree import ElementTree
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import atom
import getopt
import sys
import string
import time

calendar_service = gdata.calendar.service.CalendarService()

# your info goes here
calendar_service.email = 'user...@gmail.com'
calendar_service.password = 'password'

calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
calendar_service.ProgrammaticLogin()
event = gdata.calendar.CalendarEventEntry()
event.content = atom.Content(text=(event2))
event.quick_add = gdata.calendar.QuickAdd(value='true')

# Send the request and receive the response:
new_event = calendar_service.InsertEvent(event, '/calendar/feeds/
default/private/full')


That's it. I just made it, and it works for me, hope it works for you
too.

Dave P


On Mar 21, 10:49 pm, cedardoc <cedardocs...@gmail.com> wrote:
> This closed thread:
>
> http://groups.google.com/group/autokey-users/browse_thread/thread/ed0...

cedardoc

unread,
Mar 29, 2010, 10:58:28 AM3/29/10
to autokey-users
woops, posted that one too soon - the cancel buttons on the initial
part where you pick the date etc don't work (and I don't see in the
API documentation how to get that working - I'll look in more generic
python sites...)

On Mar 28, 9:30 pm, cedardoc <cedardocs...@gmail.com> wrote:
> Here's a good one that lets you use google calendar quick add to make
> an appointment in your appointment book without having to open your
> calendar or even your browser directly.  It uses the google calendar
> API found here:
>

> http://code.google.com/apis/calendar/data/1.0/developers_guide_python...

> calendar_service.email = 'usern...@gmail.com'

Chris Dekter

unread,
Mar 29, 2010, 9:45:29 PM3/29/10
to autoke...@googlegroups.com
What you need to do is check the retCode - it will be 1 if the user
clicked cancel:

--- code ---

retCode, date = dialog.calendar(title="Choose a date",
format="%Y-%m-%d", date="today")

if retCode == 0:


retCode, time = dialog.input_dialog("what time?", "starting at what time?")

if retCode == 0:


retCode, event1 = dialog.input_dialog("the event?", "what's the event?")

if retCode == 0:


event2 = event1 + " " + date + " " + time

try:


from xml.etree import ElementTree # for Python 2.5 users
except ImportError:
from elementtree import ElementTree

import gdata.calendar.service, gdata.service, atom.service, gdata.calendar
import atom, getopt, sys, string, time

calendar_service = gdata.calendar.service.CalendarService()

# your info goes here

calendar_service.email = 'user...@gmail.com'
calendar_service.password = 'password'

calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
calendar_service.ProgrammaticLogin()
event = gdata.calendar.CalendarEventEntry()
event.content = atom.Content(text=(event2))
event.quick_add = gdata.calendar.QuickAdd(value='true')

# Send the request and receive the response:
new_event = calendar_service.InsertEvent(event,
'/calendar/feeds/default/private/full')

--- code ---

You have a lot of unused imports there as well... your script will run
quicker (at least the first time) if you get rid of the unused
imports.

> To unsubscribe from this group, send email to autokey-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
>

cedardoc

unread,
Mar 30, 2010, 3:06:46 PM3/30/10
to autokey-users
Thank you, that fixed it (after adding one more "if retCode == 0: "
before the "try:")

Regarding the unused imports, as I'm just a "cut, paste and cross your
fingers" kind of person, I'm not sure how to tell which imports are
used and which are not.

It doesn't seem safe to assume that if the word after "import" (e.g.
"getopt") doesn't occur in the code after the import, that's the way
to tell you can delete it because I commented out all imports that
didn't follow and now it doesn't work. These were:
#import gdata.service
#import atom.service
#import atom
#import getopt
#import sys
#import string
#import time

Is the way that you know just your experience using python etc, or is
there a simpler way to know this?

By the way, thank you for this software - its nice to be able to come
over to Linux. I was one of those resisting only due to the lack of
AHK.

Dave

Chris Dekter

unread,
Mar 30, 2010, 7:13:28 PM3/30/10
to autoke...@googlegroups.com
On 31 March 2010 06:06, cedardoc <cedard...@gmail.com> wrote:
>
> It doesn't seem safe to assume that if the word after "import" (e.g.
> "getopt") doesn't occur in the code after the import, that's the way
> to tell you can delete it because  I commented out all imports that
> didn't follow and now it doesn't work.  These were:

That is in fact exactly how it works in Python - if it is not directly
referenced in the code then you don't need the import statement. You
must have accidentally commented out one that is being used. Have a
look at the 'view script error' menu option to see what is causing the
exception.

Reply all
Reply to author
Forward
0 new messages