• Hacking Together an Automatic Instagram Printer

    Yesterday I was rummaging around my magical cupboard of obsolete tech, and I stumbled upon this little beauty.



    Look familiar? It's a Dell Wasabi (aka a PZ310) that I bought years ago on a whim for $30. It's a handheld printer, and it's roughly the size of a mini portable drive. It comes with batteries, and prints via either Bluetooth or PictBridge.

    Unfortunately, at the time I didn't realise that the iPhone doesn't support bluetooth printing, and I didn't have any other phones to test it on, so it went into the cupboard. Until today.

    Using a Mac, with a combination of web services & apps, we can breathe life back into this printer, and turn it into a hashtag-based Instagram printer!

    In other words, any time there's a new photo with a certain hashtag in Instagram, this will find it, download it, crop & resize it, then print it out. All completely automagically.

    Sounds cool right? Well, what are you waiting for? Let's do it!



    What Will I Need?

    - A Mac

    - A Dell Wasabi printer (or a similar bluetooth printer, like the Polaroid PoGo)

    - Some Zink 2x3" paper (for the printer)

    - An IFTTT account

    - An Instagram account

    - Dropbox

    - Hazel for Mac (optional)

    - Photoshop CS5 or above (optional)

    Note there’s two different ways you can go about this: if you want “true” Polaroid-style prints, you’ll need to use something like Hazel as well as Photoshop/Pixelmator/Keyboard Maestro for the image composition part.

    However, if you’re happy with images being centered in the 2x3” print, then all you need is your Mac and a little bit of AppleScript.

    Step 1: Pair up the Printer

    Go to System Preferences -> Bluetooth.




    Hit the plus button to add a new device to your Mac.





    Select the Dell PZ310 printer and hit Continue.





    The printer should then pair up with your Mac. You'll probably see a screen like this for just a moment.





    Here's the weird thing; this printer doesn't recognise as a printer. Even though it will open the Scan & Print preferences, it will not install itself as a printer. That's OK.





    If you go back to your Bluetooth preferences, you should now see it's paired up. Make a note of the address of the printer. We'll need it for later.





    Step 2: Set up an IFTTT recipe

    Go to IFTTT.com and sign in. We're going to create a recipe that scans Instagram for hash-tagged photos. When it finds them, it will download them to Dropbox.





    Create a new recipe.





    IFTTT recipes work on a if this then that formula. So, our first trigger channel (aka, the 'this') in the new recipe is Instagram.





    It will ask you to authenticate against your Instagram account, so have your Instagram password handy. Then it will ask you to choose a trigger. Select the 'New photo by anyone tagged' option.





    Next, specify the hashtag you want to print. I've made up one called #mactalkstagram, basically because I don't think anyone has ever used that before.





    Next step is the action channel (aka the that) part of this recipe. Select Dropbox.





    Again, it will ask you to authenticate against your Dropbox account, so have your Dropbox password handy. Then it will ask you to choose a trigger. Select the 'Add file from URL' option.





    Now, there's a little bit of customisation here; change the Dropbox folder path to ifttt/instagram-print-start. this means all the photos ifttt finds will be dropped into that folder.





    Once you've done that, you can create your recipe. Give it a description too if you like.





    Here's what it looks like in your recipe list once you're done.





    Step 3: Create an additional folder in your Dropbox/Instagram folder:

    Because we’re using one folder for IFTTT to store the image, and another folder to print out the image, you need two folders in your Dropbox/Instagram. I’ve named mine “instagram-print-start” for the raw photos from Instagram and “instagram-print-end” for the images I’m going to print, but you can name yours whatever you like.

    (Optional) Step 4a: Create a Photoshop Droplet -- for Polaroid-style prints

    (Editor's Note: Here’s where the steps deviate a little. If you want true Polaroid-style prints -which require Hazel & Photoshop- read on, otherwise, jump ahead to Benny's steps at Step 4b instead.)

    The next part of the process is to build a Photoshop droplet to automatically resize, pad & position the photo so it looks right when it prints. What's a droplet? Well, a droplet is kind of like a little Photoshop application that automates an image manipulation task (or series of tasks) for you.

    We want to take a photo like this:





    …add some polaroid-style asymmetric white padding to the image, and turn it into this:





    Firstly, create a folder in your Dropbox ifttt folder called instagram-ready-to-print. This will be where your completed image will be saved.





    Next, open your Instagram photo in Photoshop, and pop open the Actions pane (it’s under Window -> Actions). Click the little page icon to create a new action.





    Give the new action a name.





    Now you’re recording the action. This means anything you do in Photoshop from now on is recorded, so you have to be careful!

    Firstly, to go Image -> Canvas Size... in the menu. Now apply a 140 pixel width extension (70px for each side), taking the total width to 752px. Make sure the anchor is centred. Also, make sure Canvas extension colour is set to white.





    Next, apply a second Canvas Size adjustment, adding 90 pixels to the top (for a total height of 702px). Set the anchor to the centre-bottom.





    Finally, add a 3rd Canvas Size adjustment, adding 410px to the bottom for a final total height of 1112px. Set the anchor to the centre-top.





    Now we want to export this image as a jpg (which is the only file this printer seems to accept). Go to File -> Save for Web... and set the file-type to JPEG, and crank the quality up all the way to 100.





    Hit Save... and specify to save your image in the instagram-ready-to-print folder you specified earlier. Don’t rename it.





    Finally, close the image (and don’t save it). This is important; closing needs to be a part of the automated action.





    Now you’re all done recording your action! Hit the stop button on your action pane.





    You can now select this action any time & hit play to repeat the exact steps you just did. We’re going to take this one step further and convert that action into a Droplet; a kind of mini-application which allows you to drag-and-drop an image onto the droplet to perform the same actions again instantly.


    Go to File -> Automate -> Create Droplet...





    Firstly, choose the spot where you want to save your Droplet. I’m saving it in the ifttt folder, alongside the other folders involved.





    Next, choose the action you want to save -- that’d be our Instagram Print action. Also make sure the checkboxes below match up with my screenshot.





    Hit OK to create your Droplet.


    This Droplet will now automatically create the Polaroid-style frame, and save the finished product in the instagram-ready-to-print folder. Neato!

    If you want to download the Droplet I’ve already created, you can do so here:

    https://dl.dropbox.com/u/69462/insta...nt-droplet.zip

    Step 4a (ii): Hazel

    Finally, we’re going to use Hazel to monitor our folders, and trigger the Droplet when it sees a new image appear. We’ll also use Hazel to action a Bluetooth print when the droplet shoots out an image.

    Firstly, add another folder to our ifttt folder called instagram-print-finish. This is where all images will go when you’re done with printing them.





    Now open Hazel, and add the instagram-print-start folder. Create a new rule called ‘Activate Instagram Print Droplet’





    Create a rule that looks for any images that exist into this folder, opens them with your droplet, and then moves them into your instagram-print-finish folder.





    Finally, add the instagram-ready-to-print folder to Hazel & create a new rule called ‘Print that photo’.





    This rule keeps an eye out for any images, and automatically shoots them across to the printer. It also then finally stores them in the instagram-print-finish folder, in case you want them for later.





    This is the hardest part; Applescript is needed to send the file to the printer. Remember back at the beginning we wrote down the printer number? Well, we need that number now!







    Here’s the AppleScript so you can just copy & paste it into the box, but be sure to change the device number with your own!



    Code:
    tell application "Bluetooth File Exchange"
    
            send file POSIX path of theFile as string to device "MY-DEVICE-NUMBER”
    
           
    
    end tell (* Bluetooth File Exchange *)
    
    
    
    delay 30

    Hit OK on that rule and you’re ready to go! It should start printing almost immediately.






    Finally:

    That’s it! Once you’ve set this up, as soon as an image appears on Instagram with your hashtag, it will route it’s way through your system like this:

    • Instagram -> Raw image Dropbox folder instagram-print-start (via IFTTT)
    • Raw image Dropbox -> Framed image Dropbox folder instagram-ready-to-print (via Photoshop Droplet & Hazel)
    • Framed image Dropbox -> Printer & final Dropbox folder instagram-print-finish (via Hazel & Applescript)



    The final product will be entirely automatic, and will look like this!





    Don’t have Photoshop or Hazel installed? Follow Benny’s steps below to print using Folder Actions & Applescript!

    Step 4b (i): Setup AppleScript
    If you’re doing it the low-tech way, then you need two things: Folder Actions (included as part of Finder in OS X) and AppleScript (to respond to Folder Actions).

    Essentially what we’re trying to do here is recognise when a new file has been added to a folder, which Folder Actions can do for us, and then process that file using AppleScript. If you’ve been following along so far, the combination of Folder Actions and AppleScript replaces the Hazel and Photoshop things you were doing before.

    We’ll setup the AppleScript part of things first, then add those scripts to the Folder Actions.

    What we want to do is add the following AppleScript to a new script. Either copy and paste the code below and save it into a new file, or click on this link to generate the AppleScript file for you. We'll save the file in the next step.

    Code:
    on adding folder items to this_folder after receiving added_items
    	try
    		tell application "Finder"
    			set b to displayed name of (info for added_items)
    			set a to "/Volumes/Storage/linked/Dropbox/IFTTT/instagram/raws/"
    			set c to a & b
    			set filename to quoted form of c
    			
    			do shell script "cp " & filename & " /Volumes/Storage/linked/Dropbox/IFTTT/instagram/prints/"
    			
    		end tell
    	end try
    end adding folder items to


    All we’re doing here is modifying the built-in AppleScript for recognising when a new file has been added to a folder, and copying that file into a different folder (because we don’t want to print the image as-is).

    Modify the script so that the path above is where your “instagram-print-start” folder is, I’ve called mine “raws” but yours can be whatever you like. Save that file as something like “Duplicate Image”, but into the ~/Library/Scripts/Folder Action Scripts folder so you can add it as a Folder Action Script later on (if that folder doesn’t exist, just create it). Should look like something like the following when you've done it right.



    Now repeat the process, with a slightly different AppleScript, but the same deal: either copy and paste the code, or click on this link to generate the new AppleScript file for you.

    Code:
    on adding folder items to this_folder after receiving added_items
    	try
    		set this_file to the (the POSIX path of added_items)
    		tell application "Image Events"
    			-- start the Image Events application
    			launch
    			-- open the image file
    			set this_image to open this_file
    			-- perform action
    			pad this_image to dimensions {752, 1112} with pad color {65535, 65535, 65535}
    			-- save the changes
    			save this_image with icon
    			-- purge the open image data
    			close this_image
    		end tell
    		
    		tell application "Bluetooth File Exchange"
    			send file this_file as string to device "00-13-C9-00-51-58"
    		end tell
    		
    	on error error_message
    		display dialog error_message
    	end try
    end adding folder items to


    This AppleScript is a little more complex: it still uses the Folder Action of a new item being added to the folder, but this time we’re using Image Events to pad out the image. The padding isn’t perfect (i.e. it’s symmetrical and uniform on every edge, not like the Polaroid-style prints James’ method outputs), but this is mostly a limitation of Image Events rather than anything else. After padding the image with a white border, we save the image, and send it off to the device. Make sure the device address is the one of your printer you got above.

    Save the above AppleScript into the same place (~/Library/Scripts/Folder Action Scripts), calling it something like “Pad and Print”.

    Step 3b (ii) Setting Up Folder Actions
    Now that our AppleScripts are all setup, it’s time to put together the final piece of the puzzle: Folder Actions.

    Folder Actions are pretty cool as they’re built into the OS and can do things when items are added to a folder, and so on. Combine Folder Actions with a little bit of AppleScript, and you’ve got yourself a rough approximation of Hazel.

    Locate your folders in the Finder. Right click, and select “Folder Actions Setup…”



    In the window that pops up, you’ll want to select the “duplicate image” script you saved earlier. Hit attach.



    Do the same with the “prints” folder that you’ve created (i.e. attach the “pad and print” script to the “prints” folder, so the Folder Actions Setup window looks like this:





    And believe it or not, that’s it. If you’ve setup your AppleScripts properly by modifying the correct paths of your Instagram folders in your Dropbox, and if you’ve correctly added the right scripts to the right folder, it should, in theory, just work.

    The flow diagram for the Folder Actions and AppleScript method is pretty similar, only with fewer moving parts:
    • IFTTT puts your Instagram image into your Dropbox/raws folder.
    • Once a new file lands in your raws folder, Folder Actions calls AppleScript to simply copy that file into the prints folder.
    • One a new file lands in the prints folder, Folder Actions calls AppleScript to pad that image out, save it, and then send it off to the printer.


    And voilà, the finished product. Not as elegant as James' solution, but on the plus side, doesn't require Photoshop or Hazel.



    Wrap Up:
    There you have it: two ways to hack together an automatic Instagram printer, both with their own advantages and disadvantes. A few notes:
    • Photoshop isn't strictly necessary for the first method, as you could do the same thing manually with pretty much any image manipulation app. An app such as Keyboard Maestro would even allow you to keep it all automatic.
    • Image Events isn't the best image manipulation app around, but it is scriptable. If you know of a similar free app that is scriptable and can add non-uniform padding, I'd love to hear from you.


    Editor's Note: A huge thank-you to Benny Ling for persisting & finding a way to do it for free. You're a legend!

    James Croft runs Go Make, a business helping education with technology in a post-PC world. He's on Twitter, Google+ & even LinkedIn from time to time.
  • Dropdown

  • New Forum Posts

    Mongrel

    Strange Errors in Console

    Hi Guys,

    So I was trying to work out why my VPN connection won't work and I came across these strange errors that I can't nail down.

    Mongrel Yesterday, 05:05 PM Go to last post
    RichardClopton

    T-shirt design software

    Now you dont need to take too much headache,
    You can design your t-shirt using custom tshirt Design tool. Ecommerce portal integrated tshirt design

    RichardClopton 23rd September 2016, 10:41 PM Go to last post
    PCKid

    iP7 - who's ordering what and why?

    Still happy with my iPhone 6 64GB. Also waiting for the, hopefully, big change next year. Going for a bigger plus next year. Hopefully both cameras will

    PCKid 23rd September 2016, 05:47 PM Go to last post
    TheTimp

    Gutenprint Version Not Compatible with Sierra

    Hi,

    Happy mac user here - with an interesting question..

    Just upgraded my Mac Book Pro 2014 to Sierra and got a message

    TheTimp 22nd September 2016, 04:35 PM Go to last post
    PCKid

    Old iPad to new iPad restore?

    My wife has an iPad 2 with iOS 6 backed up to her 2006 24"iMac running Snow Leopard. She's about to get a new iPad Pro 9.7" to replace it. She

    PCKid 21st September 2016, 06:19 PM Go to last post
    jezalenko

    My Bad Experience - Used Car Gallery, Car City, Ringwood

    Sorry to revive an old thread - but I've recently had some luck here. I'm trying to share the info around.

    I recently received a full refund

    jezalenko 19th September 2016, 09:48 AM Go to last post
    RichardClopton

    online t-shirt design sites.

    yah i have found inkyrobo is a good site .

    RichardClopton 13th September 2016, 05:51 PM Go to last post
    Fenne

    How to backup or copy iPad music to computer on Mac

    This is good, thanks for your share. For iPhone or ipad users, if we want to transfer or backup data to pc or Mac computer, we can use direct data transfer

    Fenne 12th September 2016, 05:14 PM Go to last post