Help with Applescript/Automator

Discussion in 'Mac Programming' started by saberahul, Jul 30, 2014.

  1. saberahul macrumors 68040

    Joined:
    Nov 6, 2008
    Location:
    USA
    #1
    I want to take all images placed into a folder and put them in a Word document one after the other.

    I was able to do this in Automator using the following steps (folder action):
    1. Get Folder Contents
    2. Create New Word Document
    3. Insert Content into Word Document (bottom of document)
    4. Save Word Document

    This works, partially. The problem is that I have over 100 image files and it takes a little more than 1 second to paste them all into the folder with the folder action. This causes the folder action to make 1 Word document for the pictures that got pasted right away, another for the next set of images, and so forth.

    How can I go about making just one document with all images inserted one after the other? I have tried using Combine Word Document, Ask for Confirmation (which does nothing on Yosemite), and Wait for User Action (which did not make any difference as even after hitting OK after 1 full minute, same thing happened).

    If someone can point me in the right direction or just give me an AppleScript code (I assume this is easy?), I'd be grateful!
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    I'm just guessing that the folder action kicks in before all the images are pasted into the hot folder right? If that's the case you can try this :

    In Automator create folder action :

    1. Folder Action receives files and folders added to your folder
    2. Run AppleScript action with the following code

      Code:
      on run {input, parameters}
      	(* Your script goes here *)
      	tell application "Finder" to set theFolder to get container of first item of input
      	-- This should make the folder action wait until files have finished copying to the folder
      	set fSizes to {0}
      	repeat
      		tell application "System Events" to set end of fSizes to size of theFolder
      		if (item -1 of fSizes) = (item -2 of fSizes) then exit repeat
      		delay 1
      	end repeat
      	return input
      end run
      
    3. Create New Word Document
    4. Save Word Documents

    Note : Tested on OS X 10.9.4 and Microsoft Word 14.0.0 with 242 image files dropped into the hot folder. It created a 27 page Word document with all the images. I'm stressing that I dropped files into the hot folder. If you want to process folders as well you'll need to change the script. It is good practice to leave the hot folder empty after processing. This avoids repeated application of the action to the same files.
     

    Attached Files:

  3. saberahul thread starter macrumors 68040

    Joined:
    Nov 6, 2008
    Location:
    USA
    #3
    Wow - thank you! Just tried with 1,005 images and it worked wonders!
     

Share This Page