• 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.
    Comments 9 Comments
    1. paronga's Avatar
      paronga -
      tickle me very impressed

      it's a shame that the non photoshop method doesn't come out as perfect. I personally really don't like all the white padding.

      BUT i can't believe how fucking awesome OS X is and that you can do that all with APPLE SCRIPT!
      jeeze what an OS!

      maybe one for people with pixlemator?

      EDIT: actually, just looking at automator (which can also be used to create folder actions and something i'm more comfortable with)
      you could change it so that you pad the image. Then crop the image before printing!
      still using all the OS X built in actions.

      maybe wana check that out?
      but yes. Very impressed. Very cute tutorial and i'm very interested in getting one of these printers now
      I really do miss having printed images etc.

      what's the running cost of these printers in terms of ink/paper?
    1. James Croft's Avatar
      James Croft -
      We looked into automator padding, but it will only pad with a black background, and is always centred both vertically & horizontally. Ditto with cropping -- there's no way to asymmetrically crop

      In terms of cost, I'm not too sure yet! I'm still running on the packs of paper I got when I bought the printer about 3 years ago! Ebay seems to turn up around $10 for 30-40 sheets, and cheaper if you buy in bulk.
    1. bennyling's Avatar
      bennyling -
      Quote Originally Posted by paronga View Post
      what's the running cost of these printers in terms of ink/paper?
      It's not too bad, I don't think they sell the Dell Wasabis anymore, but you can get a Polaroid PoGo which is pretty much exactly the same thing.

      And Polaroid PoGo paper is still somewhat readily available, there's a few sellers on eBay that sell it for roughly 30c per print.

      Quote Originally Posted by paronga View Post
      EDIT: actually, just looking at automator (which can also be used to create folder actions and something i'm more comfortable with)
      you could change it so that you pad the image. Then crop the image before printing!
      still using all the OS X built in actions.

      maybe wana check that out?
      Good idea, but the pad images in Automator pads the image with black, not white. Pixelmator doesn't seem to have the same scripting capabilities as Preview, either, so that's out.

      EDIT: hah, beaten by seconds.
    1. paronga's Avatar
      paronga -
      it appears you are correct. Searches on the topic bring me to this conversation

      Hmmm, that is a real shame. While it seams pixelmator has automator actions, it has no applescriping capabilities.

      The crop tool for pixelmator in automator will anchor it. But i guess it's a hassle to use apple script then pixelmator. And i guess you don't want pixelmator opening every time an image comes through!

      still, very nice indeed. I'm probably going to ponder how to get it perfect without using photoshop though. Hmm maybe a bash script?

      I'm definitely going to look into one of those printers. Do you recommend the polaroid PoGo?
      i thought fuji film came out with a few good products too?
    1. James Croft's Avatar
      James Croft -
      If you're comfortable with command line, and you can use MacPorts or BREW, you'll probably want to look into ImageMagick for more sophisticated command line image manipulation.

      I thought it was too complex for the scope of this tutorial, but definitely worth looking into if you're interested in digging deeper!
    1. bok's Avatar
      bok -
      What an awesome idea. I wonder if you can replicate the same thing using Shared Photo Streams and iPhoto/Aperture if you don't use Instagram.
    1. bennyling's Avatar
      bennyling -
      Quote Originally Posted by bok View Post
      What an awesome idea. I wonder if you can replicate the same thing using Shared Photo Streams and iPhoto/Aperture if you don't use Instagram.
      Should be easy enough, because the Photo Stream folder is located at ~/Library/Application Support/iLifeAssetManagement/assets/sub/ —*you should just be able to substitute that folder for your raws/instagram-print-start folder, add some checks that any new files have been added are actually images, and go from there.
    1. leene's Avatar
      leene -
      Quote Originally Posted by James Croft View Post
      We looked into automator padding, but it will only pad with a black background, and is always centred both vertically & horizontally. Ditto with cropping -- there's no way to asymmetrically crop

      In terms of cost, I'm not too sure yet! I'm still running on the packs of paper I got when I bought the printer about 3 years ago! Ebay seems to turn up around $10 for 30-40 sheets, and cheaper if you buy in bulk.
      Thanks for posting this! I was wondering if I can do this with a printed that is connected via wifi instead of bluetooth.

      Also was wondering if its possible to add a layout when in photoshop. Like a transparent overlay or something. My sons 1st birthday party is this saturday so I was looking for ways to do a photobooth type ish prints but using instagram instead of an actual photo booth but I would still want to design a layout for it and brand it.

      I have found sites such as giclie.com but it has been buggy. It doesn't detect the hashtag right away from instagram and only prints some pics that are using the hashtag. It only always worked when you emailed the picture rather than it printing instantly when someone posts to IG using the hashtag.

      I would appreciate any help! Mahalo so much!
    1. Postitman's Avatar
      Postitman -
      I am also looking to print a photo with a printer connected with a usb. How would the script look like then? I tried a couple of scripts already but can´t get it to work. Thanks
  • Dropdown

  • New Forum Posts

    lawrencium

    Apple September the 9th Event announced!!

    In all honesty, I think it has something to do with Apple containing their excitement through the plain and non-suggestive nature of the invite.

    lawrencium Today, 09:34 PM Go to last post
    lawrencium

    Do you want a bigger screen for the iPhone 6?

    The rumours also suggest something about it being implemented/accepted in stores which accept credit cards and NFC chips in general, which therefore indicates

    lawrencium Today, 09:29 PM Go to last post
    Goodbye

    Apple September the 9th Event announced!!

    I would have thought that the "say more" is hinting towards the size of the next iPhone.

    Goodbye Today, 08:27 PM Go to last post
    kerr

    Do you want a bigger screen for the iPhone 6?

    I'd be disappointed if Apple introduces NFC but only via the credit card linked to your iTunes account (rumour).

    I choose to not have a

    kerr Today, 06:37 PM Go to last post
    Warthog

    Do you want a bigger screen for the iPhone 6?

    If the iPhone 6 5.5 eventuates, I will definitely come back to the fold. Since I had the iPhone 4, I have been using the Note 2, then the Note 3.

    Warthog Today, 06:11 PM Go to last post
    Dog Knight

    Apple September the 9th Event announced!!

    Didn't they already advise this was going to happen at WWDC when announcing iOS8?

    Dog Knight Today, 03:34 PM Go to last post
    Oldmacs

    Apple September the 9th Event announced!!

    I was thinking something along the same lines... But an iWatch may do the same thing - or its Siri and siri is on the iWatch?

    Oldmacs Today, 02:46 PM Go to last post
    PurpeJes

    Apple September the 9th Event announced!!

    Maybe I'm looking too simply at this... but in the sentence "Wish we could say more" the word 'say' jumps out to me because at the end of the

    PurpeJes Today, 01:36 PM Go to last post
    kerr

    Apple September the 9th Event announced!!

    I'm confident that a 4.0" iPhone will be mentioned. Either an iPhone 6, a new iPhone 6C or just the existing iPhone 5C.

    kerr Today, 12:45 PM Go to last post
    baobab68

    Apple September the 9th Event announced!!

    I'm going to take a stab at guessing what it means: expansions to the Siri API.

    baobab68 Today, 12:08 PM Go to last post