Automator Script Uploading Images to Habrastorage: Second Coming

    Some time ago I made a script that uploads images to Habrastorage directly from the file manager. But the trouble is: after the update, it stopped working.


    But yesterday, I still got tired of uploading photos via the web interface, and I went to repair the script.
    For the solution, you must put the pluses in karma to the user avalak , who told how to do this in my question on the toaster. Toaster - Cake!

    So how to upload images now?

    Previously, the following command was used to download pictures:
    curl -F "Filedata=@/Users/vvzvlad/Documents/REVIEWS/003.jpg" ""

    With the new version of HS, it took on this form:
    curl --cookie "habrastorage_sid= fs5csqksk0hdm5mq3o91cmdm97" --form "files[]=@/Users/vvzvlad/Documents/REVIEWS/003.jpg --header "X-Requested-With: XMLHttpRequest" --header "Referer:" --request POST

    Authorization now occurs not by code, but by the content of cookies. To find out, you need to go to the habrastrange, click (in chrome) on an empty leaf in front of the address and select “Show cookie and site data”:
    Then find it in the list and copy the contents:
    And paste it into the script:

    By the way, in the previous version The script had certain problems with the names of folders and files containing spaces. To avoid this, let's do this:
    We move the file to a temporary folder, rename it to remove the spaces in the name, and load it. And after loading - delete: rm "$FILE"

    Another from the new - my picture is automatically inserted into the draft text. This is done by the following construction:
    set the clipboard to "\"image\"/"
    display notification input with title "Картинка загружена"
    tell application "Google Chrome" to activate
    tell application "System Events" to key code 9 using command down

    The first line - forms an image tag from the image address, the second shows a notification, the third - makes the Chrome application active, and the fourth virtually presses the cmd + v button.

    As usual, the service file is here . It is necessary to unzip the archive and move its contents to / Users / User / Library / Services /. Open it by double-clicking on the file and paste your cookie inside.

    However, I don’t know what to do with a cookie that goes bad after a few days. While I will copy manually.

    Also popular now: