⬆️ ⬇️

Automator service that uploads images to Yandex. Photos

To create this service, I pushed the post script Automator, uploading images on Habrastorage , or rather, here is the comment.



So, what is the difficulty of writing such a service? In that the image upload requires an OAuth token, i.e. you need to get it somehow (and save it for later use). Of course, you can create your own OAuth application and get the token manually. But this is not our method.



Recall how OAuth authorizes an application on Yandex.Files :

3. The OAuth server redirects to the specified URI by the developer, adding to it as a parameter a token or a confirmation code, which gives the right to subsequently receive the token.


Just what we need. One question remains: how do we get this token? A very simple. We need to specify in the settings of the application such a Callback URL , which will lead to the opening of our application, and already it will receive and save the token.

')

To do this, we use the opportunity of OS X applications to declare themselves URL schema handlers. For example, an application can specify that it is a URL handler of the type ypu-oauth://... , and any attempt to “open” such a URL will trigger the application to which the original URL will be passed for processing.



So let's go. First, create our application. No, no, do not rush to run Xcode, we do not need it at all. We will write the application in the purest AppleScript.



Open AppleScript Editor , create a new file and save it as a Program .







The code of our application is quite simple:



 on open location theUrl #  theUrl —    "" URL # : ypu-oauth://do#access_token=...&token_type=bearer&state=&expires_in=31536000 #  access_token  theUrl #  access_token    #       . #          end open location 




Now we need to correct Info.plist our application by adding information about the type of URLs it processes.



Right click on the saved application, select Show package contents and go to the Contents folder. Edit the Info.plist file with your favorite text editor and add the following lines:

 <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>YPU OAuth Authorizer</string> <key>CFBundleURLSchemes</key> <array> <string>ypu-oauth</string> </array> </dict> </array> 




The final content view should look something like this:







Do not forget to save the modified file!



The final step. We change the settings of our OAuth application on Yandex . Photos :







The implementation of the service is also quite simple and is described in detail in the above blog . I will add only my five kopecks. The service already receives the list of selected files, so there is no need to additionally request this list from the Finder.







Ready service, application authorizer and their installer can be found here . Tested on 10.7 and 10.9. Should work on 10.8. Standard license - WTFPL .

Source: https://habr.com/ru/post/207818/



All Articles