 Hi, everybody. Thanks to be here. And let's start with the presentation. So first, very quickly, which is the agenda for the next 30 minutes. We will talk about software automation using different tools, especially working with Python scripting. So we will see how to mix these tools with Python and how to realize some interesting procedure to speed up our daily job. This is not a strictly technical talk. It's not focused only on Python. But it's about using Python in a different way as a Swiss knife for doing whatever you want, basically. Simplifying our life and enhance our daily routine. The presentation is divided into parts. The first is a pure slideware. But I want to give you some concept about software automation. And the second part are a quick demos of some example I found pretty interesting about automation. So let's start. Let me introduce myself. My name is Giorgio Canieri. I'm an Italian developer, technical writer, US architect, blah, blah, blah. Of course, I'm a Python lover. So I decided to give this talk. And because I'm also a lazy guy, I decided to show you exactly how to use Python for automating repetitive and not so interesting task at all. Why automation? First thing first. Automating repetitive task has three main benefits. The first, of course, is that automating task, you can save time. You demand to a Python script or to a third-party tool, to do the dv jobs. And frankly speaking, a good script is always faster than you at executing tasks. Second, if you write a script to automate a procedure or a recurring job, once you test it, you can be confident that the result is the correct result. While you repeat tasks, you can occur in errors. Doing this by using automation is more safe. Of course, the keyword here is testing because you have always to test many times till you are confident with the result of an automation script. And third, automating helps you also to remain focused on what you're doing. If you automate, for example, a procedure to retrieve information from internet, you don't have to leave your IDE or your main application and retrieve the information, but just you can type a few strings and have the data back without leaving your main stream or your main process. The second question is when to automate? There are three factors that you need to consider when automating tasks or when you plan to automate a task. The first is execution time. So when a task takes time to execute, it's always a good candidate for automation. If you automate a long task, every time you run it, you save an incredible amount of time. The second factor is a frequency because also tasks that doesn't need so much time can be automated if they are run frequently during the day. So consider the short amount of time repeated by the number of times you run a task and you have always a good save of time. And third is, as I told you before, accuracy. If you have very delicate tasks and you need to rely on them, even if they are not time consuming or very frequent, you can consider automating them. So what can you automate? Fundamentally, whatever you want. I have some ideas. I'm giving to you some ideas, string manipulation. We will see it later, information retrieving. You can automate how to retrieve, manipulate, and reformat data, data manipulation, image management. We will see how it's possible to easily manage images for rotation or resizing or whatever you want and also document management because if you are used to produce often the same documents with only small changes, you can automate the mixing of data inside the document and produce new document. The tools. Python alone is not enough. You need a convenient way to run automation script and you need a convenient way to interact with them and get the result back. Shell is not a good candidate because to run a script in a shell, you need to leave your application or IDE, choose the right directory, run the script, remembering the name and the parameters of the script, grab outputs, and so on. So I think that Shell is a terrible candidate. At this point, you may think to write your own UI to interact with your script, but once again, this solution is weak because it takes time and you have to face different problems, like for example, software activation, interaction with 30-party apps, clipboard integration, reading and writing to the clipboard, Windows management, and so on. So considering both the approach very, very weak, I will propose you the use of 30-part tools and I will show you a more convenient way to interact with automation script, tools, and so on. What are these tools I'm talking about? I divided these tools in three categories. The first category is command line tools. I mean tools that are useful to launch command macro and so on without leaving the application you are using in foreground. These tools are, for example, Alfred for OS X, but there are many different tools for each platform. They create a virtual command line, positioned in the center of the screen, and which automatically gains focus. So you have only to press a combination of keys, activate these interface and do whatever you want. The second cluster are text expansion tools, tools that doesn't have a real interface, but that can trap your keyboard typing and do something when a specific combination of task, sorry, of keys are pressed. So I will show you later how it's possible, for example, to automate link creation, retrieving information from browser, URL shortening, and so on. And the third cluster in the end are tools that can fire action on our script at a particular moment when the system change. Generally, when you put a file in a folder, you can trigger an action, and this action can do different things on the files that are put inside this folder. What software do we need? I'm a Mac user, so I will show you tools for OS X, the first column, the one in green. But I wrote this table where you can see that there are alternatives for Linux and Windows, and the approach is quite the same. So you have command line utilities for Linux and Windows, text expansion utilities for Linux and Windows, and file system triggers for Linux and for Windows, I don't know because I wasn't able to find something similar to Hazel or Maid. The approach is the same. Once you think how to automate, and once you understand which are the parameters and the best practice you need, you can develop the same script on Westend or on Linux and on Windows. About command line, I will show you two tools that are Alfred and Keyboard Maestro. They act quite in the same way. I prefer Alfred for input management while I prefer Keyboard Maestro for output management. I will show you some examples so you can decide which is the best for you. So the first tool is Alfred. Here I have some screenshot. As I told you before, Alfred is very... Do we have the pointer? Yes. Okay. It's very simple. When you type a combination of keys, it opens a command line in the middle of the screen. We'll see it in the demo in the next minutes. And you can type a command and something happens. Which is the magic that happens. This is a workflow written in Alfred, for example, where you can define some input. In this case, the word home. You can define a process or actions that need to run. In this case, our Python script and then you define an output, which is generated translation. Keyboard Maestro works in a similar way. It has a workflow. It's a little bit less graphic. It has a top-down logic where you put blocks inside the workflow, but it's quite the same. You define a trigger for the macro, for the workflow, for the automation process. You can call it in the way you prefer. And the actions are run exactly in this sequence with a top-down sequence. Third tool, TextExpander. It's different from the previous two because you have to decide which is the abbreviation. And in every application, you type this abbreviation. For example, in a browser, text box, or in a text editor, or in your favorite IDE. It fires this script and replace the string typed with the result of the script. That's why it's called TextExpander. Last but not least, we have a Hazel that works as a workflow manager triggered by FileSystem. In this example, I define a folder that I have on my Mac called CDN and then define an action called UploadImage. So every time I move a file inside this folder, this action is fired. And how the action works, it checks if the file that is copied inside the folder is the right type and then execute this script. In this example, it automatically takes the file, I pass it to the folder, check if it is an image file, and then uploads it to my content delivery network. Some ideas, now I stop with the slides and we can move to the demo part. And I divided the demo I will show you in three categories representing the three main blocks of software automation tools. And we will see command line tools, text expansion, and automated procedure using FileSystem triggers. So, let me switch from the two modes. Okay, so first example is NetInfo. Wherever I type command and spacebar, Alfred opens, and as I told you before, it's a command line that is conveniently placed in the middle of my screen where I can type, for example, NetInfo and it automatically produce this output with all the information about my network. How does this work in a very, very simple way? If I open the workflow manager in Alfred, you can see the NetInfo action, which is only a one block action that fires this script. The resolution is not the best point of this projector. But as you can see, it runs some system commands to gain information, SCU tools, for example, from network or VPN and so on, and then it passes to a convenient object which renders the output. So, every time I write a NetInfo, it fires these scripts, gets the information, and produces this output. Very, very easy. The only thing you have to take care of is the format of the output because with Alfred, you need to use these syntax. So, when an input is passed to the script via a query, it returns an output that needs to be a valid XML of this type, sorry. This is the XML that the Python script needs to generate. You have one or more items that are the rows of the output where you can specify a title, a subtitle, an icon, and you can specify also the value that is passed to the next step of the workflow when a row is clicked. And then you can also specify if auto-completing or not. So, you don't need to type all the commands but just the first parts. Second example, just to show you other capabilities. When I type TZ, automatically, it creates a list of timestamps in different time zones. I'm used to work with people coming from different areas of the world. So, without leaving my workflow opening, for example, a browser to check the time and so on, I just can type TZ and it does what I need. Third example is translate. Assume that you are writing an email or writing a document or something like that and you need to translate a word. You can type TR and then the word. For example, casa, which is Italian, means house, which is the same in English and Deutsch, mezon and so on. You can also translate sentences, comestas, how are you, and so on. Unfortunately, I don't speak neither Deutsch nor French. And once you select one row, it's copied to the clipboard and you can paste wherever you want. So you don't have to leave to go on Google Translate, type the sentence and so on. How is it done? Translate. I don't want to waste your time, but this is a simple script that checks the translation with Google Translate. I can also create simple notes, for example. If I just want to remember to call my friend Mario, for example, I can type call Mario and automatically, sorry, new note called Mario, which is the typical Italian name, and it automatically adds the action to a note in the script book. Very, very simple. We can go on currency converting. It's easy to know how much is 1,000 euros. It fires a script, which goes on Yahoo, in this case, I think. It uses the Yahoo app and does some calculation and outputs it to the screen. Now, let's see something more interesting for you developers. Pretty fine. Consider I have this JSON, for example. This is the JSON. This is a minified version of the JSON. I need it to pretty print it. How can I do that? I can simply copy it to the clipboard, then type, pretty fine, then choose JSON, and when I paste, I have the pretty fine version of this JSON. I can do the same with SQL, for example, SQL. I work with database. I have query writing in the worst way possible in the world. Pretty fine, SQL, and then paste. I have a script that has a procedure inside that takes the past SQL and provides the pretty fine output. Last example. Okay. Very, very easy. And you don't have to rely on a specific tool or IDE or something like that. You can pretty fine whatever you want in every tool. Text managing. Consider you have this list, for example. Okay. This is a list of member country of the UI union. If you need to do some operation on each line of this list, you can conveniently copy the list, then activate Alfred. You can use the txt command, and then you see in the subtitle, you can use text or line to manage the list. If you use text, it considers all the list. If you use line, it considers every line, each line, sorry, of the list. So, for example, if I type, plus line, plus... Okay. Each line, it depends a single quote at the beginning and a single quote plus a command at the end. So, I converted this list to a more SQL friendly format of list. But I can do whatever I want using the Python syntax. For example, if I want to remove the single quote and the comma, I can do line one, two, minus two. And it's the same. I'm using the advanced string manipulation future of Python to automate this simple task. And the script, when it's fired, takes the list, splits it using carriage return, and executes the command I pass on every single line. Once more, txt line, for example, replace space with underscore simple. Next example, creating document. As I told you before, I have the necessity to create a different version of documents, just changing symbol part of documents. So, what I did is to create a template and then fill this template with information. In this case, I can type docs. It asks me which is the project ID, one, two, three, four. Tab, it asks me the author, Gianluca. Project name, go to the moon. Project area, dreams, generate fs. And in the alt alias, I have my document generated. Okay, you see project ID, project name, author, and so on. Okay, I know what you're thinking. You're thinking, yes, but writing this automation script takes time. I know, because to write, for example, this script, it took me about three hours. But if you consider that I run this script many, many times during the year, I can save a bigger amount of time than the three-hour needed to write down the script. Then I can also act on files, for example, not only on strings. If I go to, sorry, desktop, EuroPython, I have two images, the cathedral of my town. And if I type option and space bar, I created these actions. Copy file names to Clidboard. Copy file names to Clidboard with that path. Rotate clockwise, rotate counterclockwise. Okay, I type rotate, and it automatically rotates the image. How it works, when I type option and command bar, automatically pass to a Python script the name of the file, and then I can use PIL library or whatever you want. I think I'm using your image magic to rotate the image and to do the proper command. Other example, Keyboard Master, as I told you before, is my preferred tool for output. So if I type command and M, automatically it creates a personal forecast with the results for the next hours and next days. Nothing tremendously complicated, of course, but I want to show you how it's possible to output also a more detailed bunch of informations that are not only the single lines you have seen with Alfred before. You can also work on CSV file, for example. This is a script I created for conveniently display CSV files, and you can do whatever you want. Last example, Text Expansion. I have defined some macros that interact with my browser. This is the first Italian newspaper, and if I'm typing, for example, in my text editor, double commas C title, it expands with the Chrome title. If I type C URL, it expands with the Chrome URL or C link H for... Sorry. C link H for an HTML link or C link M for a markdown link. So I don't have to copy and paste the single titles and URLs or C short for a handy short link. If you see Text Expander, it works pretty, pretty simple. Get Chrome URL. When C URL is typed, this script is fired, and it can interact with Google Chrome using Apple Script in this case because it calls an external script. Last category are File System Triggered Actions. Okay, I created this folder called Resize, and each time I copy, for example, an image inside this folder, the images are automatically resized because I have a trigger that automatically takes the images pasted to Hazel and fires a Python script that does the magic. Okay. These were just ideas of what you can automate. I'll show you some needs that I had and that I solved using automation, but you can do fundamentally whatever you want. And the only thing you have to consider is how much time do you spend repeating a task and then how you can automate it. Just as a last sentence, remember that you can do the same thing on mobile devices because, for example, on Android, you have Tasker, on iOS, you have the workflow, Pythonista, and so on that are tools that can automate repetitive tasks and also on mobile devices. We have no time to talk about it, but you can use these tools. And, for example, Pythonista and Tasks supports also Python. Okay, thank you all. I'm finished. Yes, off the script. Yes, he's asking me if there is a repository for the scripts. Yes? Yeah, you have a repository for each tool. For example, if you go on TextExpander site or on Alfred's site, you have specific repositories. Maybe the solution is not writing using Python but other languages, but you can find whatever you want. If you want to look at this example in the presentation, there's a repository for the presentation. Okay, or on my site from the next Monday you can find all the gist of the example I showed you. Okay, thank you.