2013-12-10

Moving Outlook messages with one click (2)

I now have Outlook 2013, multiple accounts and have upgraded from Exchange server 21007 to 2010 which meant my short cut macros have got lost.  so I am starting again and revising my old post.

I need to create a macro to move the current e-mail to a specified folder, normally Inbox Done as a sub folder of my inbox.  This allows me to keep my inbox clear and not read emails twice and not action them.

1) Create a macro

a) Show the developer tab in Outlook.
Microsoft help is here.

File->Options->Customize Ribbon>Developer (checked)

b) Developer –>Macros –> (type new name) –>Create
This creates a stub and open it in the VBA editor, eg:

Sub test()
  MsgBox "Hi"
End Sub

This can now be run from the developer macros window.

I couldn’t find the general short cut tools that used to be there,  However if you customise the Quick Access Tool bar then Alt+n will give you the nth button.  So in my case Alt+4 gives me my macro.  This works across all of my inboxes.

2) Changed the code to below for moving the message in each mail account:

Sub test()
'Sub MoveSelectedMessagesToToDo()
    On Error Resume Next

    Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder

    Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem

    Set objNS = Application.GetNamespace("MAPI")

    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

    If Application.ActiveExplorer.Selection.Count = 0 Then
        'Require that this procedure be called only when a message is selected
        Exit Sub
    End If

 
    For Each objItem In Application.ActiveExplorer.Selection
        If objFolder.DefaultItemType = olMailItem Then
            If objItem.Class = olMail Then
                'Find which account this is in
                Set mailParent = objItem.Parent
                'Find the matching object folder for that account
                Set objFolder = mailParent.Folders.Item("Inbox Done")
                'if found the folder then move else error
                If objFolder Is Nothing Then
                    MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
                Else
                    'move the item to that folder
                    objItem.Move objFolder
                End If
                Set mailParent = Nothing
                Set objFolder = Nothing
            End If
        End If
    Next

    Set objItem = Nothing
    Set objFolder = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing

End Sub

I also programmed the Microsoft keyboard to provide a hot key for the Alt+4 which mean a single keystroke to do the work.

Apart from my old post, I have used:

http://www.vogella.com/articles/MicrosoftOutlookMacros/article.html

2013-01-17

Gauss cannon

I got some Buckyball cubes for Christmas and I just wanted to remember a good link on building a guass cannon: http://scitoys.com/scitoys/scitoys/magnets/gauss.html

2013-01-14

staticgenerator

I am building a static website but want to use a generation tool to build all the pieces.  I am using Python and originally looked at Hyde.  But I had difficulites and want to learn the Django frameworks. So instead of using Hyde, I am going to try out creating sites using Django and then using staticgenerator to take copies. pystatic is a newer alternative.

The original documentation at http://superjared.com/projects/static-generator/ has gone but the project is here:

http://pypi.python.org/pypi/staticgenerator/1.4.1

and there is a clone here:

http://superjared.com/projects/static-generator/

I have copied the documentation here from a Wayback Machine archive of the original:

http://web.archive.org/web/20101221135325/http://superjared.com/projects/static-generator/

StaticGenerator for Django

StaticGenerator is on GitHub!

Introduction

How many CPU cycles do you suppose are wasted on blogs that are generated every request? Wouldn’t it make more sense to generate them only when they’re updated? StaticGenerator is a Python class for Django that makes it easy to create static files for lightning fast performance.

Download

You can get StaticGenerator using easy_install:

easy_install staticgenerator


Or download from the cheeseshop.



Usage



There are two ways to generate the static files. Both setups first require WEB_ROOT to be set in settings.py:



WEB_ROOT = '/var/www/example.com/public/'


Method 1 (preferred): Middleware


As of StaticGenerator 1.3, Middleware is available to generate the file only when the URL is requested. This solves the 404 Problem (see below).



First, add Regexes of URLs you want to cache to settings.py like so:



STATIC_GENERATOR_URLS = (
r'^/$',
r'^/(blog|about|projects)',
)


Second, add the Middleware to MIDDLEWARE_CLASSES:



MIDDLEWARE_CLASSES = (
...snip...
'staticgenerator.middleware.StaticGeneratorMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
...snip...
)


Note: You must place the StaticGeneratorMiddleware before FlatpageFallbackMiddleware if you use it.



When the pages are accessed for the first time, the body of the page is saved into a static file. This is completely transparent to the end-user. When the page or an associated object has changed, simply delete the cached file (See notes on Signals).



Method 2: Generate on Save


The second method works by saving the cache file on save. This method fakes a request to get the appropriate content. In this example we want to publish our home page, all live Posts and all FlatPages:



# Passing url, a QuerySet and Model
from staticgenerator import quick_publish
quick_publish('/', Post.objects.live(), FlatPage)


Deleting files and paths is just as easy:



from staticgenerator import quick_delete
quick_delete('/path-to-delete/')


Note: Directory deletion fails silently while failing to delete a file will raise an exception.



The “404 Problem”


The second method suffers from a problem herein called the “404 problem”. Say you have a blog post that is not yet to be published. When you save it, the file created is actually a 404 message since the blog post is not actually available to the public. Using the older method you’d have to re-save the object to generate the file again.



The new method solves this because it saves the file only when the URL is accessed successfully (read: only when the HTTP status is 200).



Using Signals


Integrating with existing models is easy using Django’s signal dispatcher. Simply create a function to delete your models, and connect to the dispatcher:



from django.contrib.flatpages.models import FlatPage
from blog.models import Post
from django.db.models import signals
from staticgenerator import quick_delete

def delete_index(sender, instance):
quick_delete(instance, '/')

signals.post_delete.connect(delete_index, sender=Post)
signals.post_delete.connect(delete_index, sender=FlatPage)


Every time you save a Post or FlatPage it deletes the static file (notice that I add ‘/’ so my homepage is deleted as well). What happens when a comment is added? Just delete the corresponding page:



from django.contrib.comments.models import Comment, FreeComment

def publish_comment(sender, instance):
quick_delete(instance.get_content_object())

signals.post_save.connect(publish_comment, sender=Comment)
signals.post_save.connect(publish_comment, sender=FreeComment)


Configure your front-end



Sample Nginx configuration


This configuration snippet shows how Nginx can automatically show the index.html page generated by StaticGenerator, and pass all Django requests to Apache.



# This example configuration only shows parts relevant to a Django app
http {

upstream django {
# Apache/mod_python running on port 7000
server example.com:7000;
}

server {
server_name example.com;
root /var/www/;

location / {
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (!-f $request_filename) {
proxy_pass http://django;
break;
}
}

}

}


It’s not for Everything



The beauty of the generator is that you choose when and what urls are made into static files. Obviously a contact form or search form won’t work this way, so we just leave them as regular Django requests. In your front-end http server (you are using a front-end web server, right?) just set the URLs you want to be served as static and they’re already being served.

2013-01-13

Installing Hyde for static websites.

Hyde seems an excellent fit for drummonds.net for producing static sites.  It is based on Python and Django.  The installation instruction as reported by Philip Mat are reported to be mixed so I decided to follow his and see how it goes.  I was also going to install it on Windows. I have installed git (short time since my computer was rebuilt) pip,Django,pyYAML,markdown

I put into \python27\scripts with the command:

git clone https://github.com/lakshmivyas/hyde.git

I downloaded the sample code

git clone https://github.com/philipmat/jekyll_vs_hyde.git

I used mongoose.exe to run the code and it worked well on http://localhost:8080/


There was also blogofile and pelican as alternative packages.

2013-01-04

Sample Python script to control Photoshop

I have been using Python to script Photoshop and came across something that wasn’t immediately obvious to me:

A sample section would be:

// Create a new 2x4 inch document and assign it to a variable
var docRef = app.documents.add( 250, 33 )

which I got to work as:

# Create a new 2x4 inch document and assign it to a variable.
docs = psApp.Documents
docRef = docs.Add(250,33)

you are not able to two level of indirection on COM objects but keep need to making Python objects of the references.

The complete sample code is:

import win32com.client

psApp = win32com.client.Dispatch("Photoshop.Application")

# Remember current unit settings and then set units to
# the value expected by this script
originalRulerUnits = psApp.Preferences.RulerUnits
psApp.Preferences.RulerUnits = 1 # 1= psPixesl, 2 = inches

# Create a new 2x4 inch document and assign it to a variable.
docs = psApp.Documents
docRef = docs.Add(250,33)

# Create a new art layer containing text
layers = docRef.artLayers
artLayerRef = layers.add

artLayerRef.kind = 2 #Text layer
# Set the contents of the text layer.
textItemRef = artLayerRef.TextItem
textItemRef.Contents = "Hello, Web!"

# Restore unit setting
psApp.Preferences.RulerUnits = originalRulerUnits