• 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

    Udbkrty

    Describe your backup system

    As i know, the backup means export data from android to computer or another phone , the an effective method is reply on the transfer tools to export these

    Udbkrty 6th December 2016, 06:31 PM Go to last post
    crookintheguts

    Macintosh Plus - blown power supply - please help

    Hi there yes and yes. I've give up on fixing the power supply on the plus but I'm thinking of putting the Mac plus board into a classic chassis and see

    crookintheguts 5th December 2016, 07:09 AM Go to last post
    alex_business2010

    Computer or program crashed? Post your crash logs.

    SINA SALEHI Syncis fell into his lap when he was 19. At the time, he was a student and working a part-time, temporary job. When he was first introduced,

    alex_business2010 5th December 2016, 05:29 AM Go to last post
    alex_business2010

    •••••• Switchers FAQ ••••••

    VANESSA ARNOLD is a Southern California native born in the Los Angeles area. At the age of 12, her parents moved the family to their home country of

    alex_business2010 5th December 2016, 05:28 AM Go to last post
    alex_business2010

    Transferring contacts from Android to iPhone

    ARSHO was born and raised in Lebanon, and like most people from the region, immigrated to the United States 30 years ago due to the Civil War. When I

    alex_business2010 5th December 2016, 05:27 AM Go to last post
    opleox

    iPhone Music Transfer without iTunes

    iTunes is one of the best tools to transfer music from your computer or Mac to you iPhone and manage the songs well. However, it requires you to pair

    opleox 30th November 2016, 04:49 PM Go to last post
    DarkAvenger

    iMac 17" 2.0GHz (Late 2006) - Questions about screen quality and performance

    Can anyone tell me what the screen quality is like on this iMac? I have the info for the viewing angles and brightness, but am unable to find any info

    DarkAvenger 30th November 2016, 12:51 PM Go to last post
    DarkAvenger

    Protective hard cases for iBooks/Powerbooks

    Does anyone know if anyone manufactures/sells snap on hard cases for the old iBooks and Powerbooks? I know these are readily available for Apple Intel

    DarkAvenger 29th November 2016, 02:10 AM Go to last post