Hello!
As it is known, programmers are people who do not look for easy ways. Recently, I had a need to automatically upload freshly made screenshots to my ftp (namely your own and no other). The long search for software, the decisive task, for OS X via the Internet led me to a slight depression. I didn’t even look for paid software, because I don’t want to pay for features that I can write myself, and free software hit me, to the very bones, with its curvature: the screens were not loaded the first time, sometimes only half of the screen was loaded and, in general, with my a penchant for perfectionism, to take a screenshot of a window and not to see on it a beautiful, beautiful shadow, which leaves the standard OS X utility - this is hell. Therefore, it was decided to take the saturday evening personally with the solution of this problem.
Without thinking for a long time, I remembered the amazing OS feature from Apple - Automator and decided to automate uploading files to FTP and tell the habrasocommunal machine and apple users who were unaware of it, so the finished file, which can be simply run and everything happens, will be instructed and an explanation of what was happening in order to teach us how to use the utility and inspire others to automate actions in their system.
')
Under the cut theory, practice and a lot of pictures.
Automator - A kind of shell script wrapper for Apple’s * nix, allows you to automate everything, absolutely any user movement. Once upon a time I used it to build my graduation project on Node-Webkit, the automator allowed me to rebuild the project by pressing the hot key combination, pack it into a * .nw archive and immediately launch it.
Some theory
There are several types of scripts in Automaton that you can create:
1. Workflow - A simple source of action, which we will program.
2. Application - Totzhe workflow, only it can be run and it will work autonomously in your OS X
3. Service - All the same, only the script will be available in the “Service” tab of the programs that you select when creating the script (you can hang up the shortcuts for this thing later)
4. Printing Plugin - Workflow, which will be available in the print window
5. Folder Action - a hook that will be launched as soon as the folder is updated (it will be added, the file will be deleted)
6. Celendar Alarm - there is nothing to say, so it’s understandable: we create a workflow that works on an event in the calendar (cron task itself)
7. Image Capture Plugin - workflow, which is available in the camera image acquisition window (takes the captured image as an input)
And now a little practice.
It is clear that we need to catch the action of creating a screenshot and immediately after it - upload a screenshot to the server, so our choice of the type of script is Folder Action.
By default, all screenshots are created in the desktop folder and it is clear that you cannot hang a hook to upload a file on ftp to the desktop so as not to trash your server, so we will have to reconfigure the standard screenshot creation utility:
- Open Terminal
- Create a screenshots folder in the ~ / Pictures folder and send there all the screenshots that the utility will create:
mkdir ~/Pictures/screenshots && defaults write com.apple.screencapture location ~/Pictures/screenshots
Now our screenshots will be created in this folder.
Go to Automator itself and do the following:
- Create Finder Action
- In the open window, we see a menu with a collection of actions and a workspace. We need only 2 actions: “Run Shell Script” and “Display Notification”, they are located in the “Utilites” section. Add them by simple drag and drop.

- In the selector at the very top of the workspace select the folder that we will follow

- In the block "Run Shell Script" set "Pass input: as argument "

- In the “Run Shell Script” block itself, you need to write an sh script that will upload files to the server, I will not list it here, because the topic of the article is different. Here is a link to github , where you can get it, read the comments, it says how to configure it for your ftp server. The script will download the new screenshot and copy the URL to it to the clipboard.
- You can write anything in the block “Display Notification”. This function will display a standard notification with your text.

- Save
That's not all. Now we need to tie the hook to the folder, to do this, right-click on the folder, select the Service-> Folder Actions Setup ... item and select the script that we just created
In order for everything to work it is necessary to restart the computer.
And everything, we make a screenshot as we did before and it will automatically be uploaded to your ftp server.
PS I want to know whether more articles are needed about what and how you can do with the help of Apple Automator and about other features of OS X that they say little about?