open file with droplet piece by piece

Discussion in 'Mac Programming' started by vloryan, Jul 29, 2014.

  1. vloryan macrumors member

    Joined:
    Jan 11, 2014
    #1
    hi guys, i would like to shrink pdfs from a specific folder using a droplet and SHRINKPDF (http://www.macupdate.com/app/mac/9206/pdf-shrink). I cannot open all PDFs from that folder at once because SHRINKPDF can handle only one at a time. Now: how can i solve this using APPLE SCRIPT and AUTOMATOR?

    > Shrink all PDFs from folder XY with SHRINKPDF.
    > Open ONE PDF with that droplet
    > Open NEXT PDF with that droplet as soon as LAST PDF finished shrinking

    Hope you guys know what i mean :)

    Thanks for your help!
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    No not exactly. Have you looked at the PDF Shrink 4 User Guide?

     
  3. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #3
    problem is that when as soon as more than one file uses the droplet at the same time, only the very first file will be shrinked. others are ignored. that is why i'd like to have the use the droplet one by one. :(
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    I made a test droplet in PDF Shrink Version 4.8 (Build 9518) and dropped 5 PDF files on it. Works just fine here. I even made a screen recording to show it in action.
     

    Attached Files:

  5. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #5
    thanks for your efforts. using several files at once manually on that droplet works, yes. but using an folder action in AUTOMATOR, only the first file will be shrinked. All other files are using the droplet while the first file gets shrinked and are then ignored. That is my problem ;(
     
  6. kryten2, Aug 1, 2014
    Last edited: Aug 1, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    You should have mentioned that in your first post. Anyway, here's a possible solution :

    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
      	-- Change to where your droplet app is located. Mine is in the Documents folder
      	tell application "Finder"
      		open input using application file "PDF Shrink Droplet.app" of folder "Documents" of folder "kryten" of folder "Users" of startup disk
      	end tell
      	
      	activate application "PDF Shrink"
      	delay 1
      	tell application "System Events"
      		tell process "PDF Shrink"
      			-- Check to see if the Active button is focused to count the rows
      			if focused of radio button "Active" of tab group 1 of window "Queue" is false then
      				set focused of radio button "Active" of tab group 1 of window "Queue" to true
      			end if
      			-- Wait until all files are processed
      			repeat while (count rows of table 1 of scroll area 1 of tab group 1 of window "Queue") > 0
      				delay 1
      			end repeat
      		end tell
      	end tell
      	
      	return input
      end run
      
    3. Move Finder Items to Trash

    Note : Tested on OS X 10.9.4. You'll need to allow Folder Actions Dispatcher to control your computer. 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:

  7. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014

Share This Page