Simple applescript problem - what did I do wrong?

Discussion in 'Mac Apps and Mac App Store' started by Ianarchy, May 23, 2012.

  1. Ianarchy macrumors newbie

    Joined:
    May 20, 2012
    #1
    I want to launch Adobe Distiller when a file is dropped into a folder. I'm a complete novice at applescript, but through my research it seemed like this should do the trick:

    on adding folder items to this_folder after receiving added_items
    tell application "Acrobat Distiller"
    activate
    end tell
    end adding folder items to

    I put it in the action script library, attached it to the folder and it does absolutely nothing. What did I do wrong?
     
  2. kryten2, May 23, 2012
    Last edited: May 23, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Why another new post?

    I guess the Watched Folder wasn't what you were looking for? Anyway here's the script. You'll see that it is a little more complicated then you imagined.

    Code:
    on adding folder items to this_folder after receiving these_items
    	tell application "Finder"
    		if not (exists folder "Out" of this_folder) then
    			set OutFolder to (make new folder at this_folder with properties {name:"Out"}) as alias
    		end if
    	end tell
    	if folderReady(this_folder) then
    		repeat with i from 1 to number of items in these_items
    			set this_item to (item i of these_items) as alias
    			--		set this_item_posix_path to POSIX path of this_item
    			if this_item is not the OutFolder then
    				tell application "Acrobat Distiller 7.0"
    					activate
    					Distill sourcePath POSIX path of this_item destinationPath POSIX path of OutFolder
    				end tell
    			end if
    		end repeat
    	end if
    end adding folder items to
    
    on folderReady(tFolder)
    	set myFolder to tFolder as alias -- use the path to the folder that's loading
    	set firstSize to size of (info for myFolder) --get initial size
    	delay 5 --wait 5 seconds
    	set newSize to size of (info for myFolder) --get a newer size, bigger
    	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
    		set firstSize to newSize --new base size
    		delay 3 --wait three seconds
    		set newSize to size of (info for myFolder) --get a newer size
    	end repeat --once the sizes match, the transfer is complete
    	return true
    end folderReady
    
    Replace "Acrobat Distiller 7.0" with your version of Distiller.
     
  3. Ianarchy thread starter macrumors newbie

    Joined:
    May 20, 2012
    #3
    Kryten, thanks again my friend.

    Actually the watched folder was working well, the issue is that Distiller has to be open and running in order for the watched folder to work. So I was just trying to launch Distiller on file drop so that it would open automatically and watch the folder.

    This script you sent over looks great and it has compiled without error, but it is not launching Distiller. I don't know why but I feel like no folder action scripts are working on my Mac. I've done everything the right way according to the tutorials I've seen. Is there a universal on/off switch for folder scripts?
     
  4. Ianarchy thread starter macrumors newbie

    Joined:
    May 20, 2012
    #4
    OK, so the script seems to do what Kryten said it would, but the problem is the folder action only launches if applescript editor is open. I've played around with this for awhile, even reset the computer, but nothing happens unless applescript editor is open first.

    How do I get around this?
     
  5. kryten2, May 24, 2012
    Last edited: May 24, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #5
    Ok, I'm going to ask a few questions. Please answer them.
    1. What version of OS X are you using eg Leopard, Snow Leopard etc
    2. Did you save the script when you put it in script editor?
    3. If you saved the script where did you put it?
    4. This is a folder action script so you need to attach it to a folder. How did you do that? Post screenshots of your actions. You can use this to clarify things please use it.

    I'm on Leopard and folder actions on Leopard are a big PITA. I have to put my folder action scripts in this location or they don't work : "LeopardFirewire:Library:Scripts:Folder Action Scripts:Distiller folder action.scpt"
    LeopardFirewire is my hdisk --> Library is a folder --> Scripts is a folder --> Folder Action Scripts is a folder and Distiller folder action.scpt is you guessed it the name of the script.
     

    Attached Files:

  6. Ianarchy thread starter macrumors newbie

    Joined:
    May 20, 2012
    #6
    Kryten, thanks again for your awesome help and detailed explanations.

    I am running OSX Lion. Folder action scripts seem to be a problem on this one, too.

    I did quite a bit of research before and after posting here, so, yes I attached the folder action script just as shown in the pictures, making sure everything was checked properly.

    I copy and pasted the script you wrote to Applescript Editor saved it to Desktop then dragged it into the Folder Action Scripts folder, which is in the same location on my computer as yours. I've played around with the script, tried a few different things, but still no reaction.

    What I did discover that the pre-made folder actions scripts seem to work all right and I also noticed that as soon as the script was opened in Applescript Editor it launched Distiller, but only then.

    Do I need to change the names of tags like This_Folder to the exact folder location?

    Thanks again for all your help.
     
  7. kryten2, May 26, 2012
    Last edited: May 26, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    Strange very strange. I wouldn't have given you the script if it didn't work. I tested it and it did work on my Leopard machine.

    No you don't need to change this_folder. It's a variable that identifies the folder that received the items. You're on Lion so you can loose the folderReady handler. On Leopard folder actions kicked in while items were still being copied. That's a safety I used but Apple changed that behaviour in Snow Leopard and I guess it's still in effect on Lion.

    You can see in the script that a folder named "Out" is created to hold the converted pfd before we loop through the items. Is that folder created if you drop a postscript file in the folder you attached the script to?

    Can you try this script? Just copy to script editor and run it. Do you see the dialog box when it runs?

    Code:
    --choose a folder that has your postscript files
    set this_folder to choose folder
    --choose some files in this_folder
    set these_items to choose file default location this_folder with multiple selections allowed
    tell application "Finder"
    	if not (exists folder "Out" of this_folder) then
    		set OutFolder to (make new folder at this_folder with properties {name:"Out"}) as alias
    	end if
    end tell
    repeat with i from 1 to number of items in these_items
    	set this_item to (item i of these_items) as alias
    	--		set this_item_posix_path to POSIX path of this_item
    	if this_item is not the OutFolder then
    display dialog "Testing"
    		try
    			tell application "Acrobat Distiller 7.0"
    				activate
    				Distill sourcePath POSIX path of this_item destinationPath POSIX path of OutFolder
    			end tell
    		on error the error_message number the error_number
    			display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
    		end try
    	end if
    end repeat
    
     
  8. Ianarchy thread starter macrumors newbie

    Joined:
    May 20, 2012
    #8
    Yes, that's what I thought in with the This_folder options, from what little I understand of applescript that seems to be a sort of universal command.

    So, I ran the script in Applescript Editor as you said. It first prompts me to choose a folder then a file. On the first run it came up with an error, which unfortunately I hit close before I copied it down. The second and third time I ran it, everything seemed to work fine, I got the "testing" dialog boxes as it says in the script. After I hit OK, Distiller launched. Oh, and Distiller also launched when I first pasted and compiled the script.

    I tried attaching this script to a folder and I did nothing at all until I opened Applescript Editor, then Distiller launched again. But attaching this script to a folder and dropping an item in does not cause the script to activate, at least not until Applescript Editor is open first, just like before.
     
  9. kryten2, May 30, 2012
    Last edited: May 30, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #9
    The script in my last post is NOT a folder action script. It was made to run from script editor and for testing to see if it got to the display dialog line. You say the second and third time you ran it it worked but you didn't say if it actually created pdfs from the postscript files which is what you want to achieve. The only thing I have left up my sleeve is to ask you to test a simple folder action script. Make the necessary changes, attach it to a folder and drop a file into the folder. Doesn't matter what kind of file. It should launch Acrobat Distiller. I already asked you to post screenshots to make things clearer. I'll ask it again. Post a screenshot of the Adobe folder in Finder where your Acrobat Distiller is located. Also post the code you're using so I can see any changes you made. Good luck.

    The simple folder action script :
    If you paste this in script editor and click the hammer to compile it shows a dialog box to choose an application with the question Where is Your Acrobat Distiller here? If Acrobat Distiller is not in the list, browse to the location where it is and click choose.

    Code:
    (*
    folder action scripts need this on adding folder items to handler without this handler no folder action!
    *)
    on adding folder items to this_folder after receiving these_items
    	-- insert actions here
    	-- change tell application line!
    	tell application "Your Acrobat Distiller here"
    		activate
    	end tell
    end adding folder items to
    
     

    Attached Files:

  10. Ianarchy thread starter macrumors newbie

    Joined:
    May 20, 2012
    #10
    Kryten, thanks a lot, I'll have a play around with it and post some screen shots of what you requested.

    The script you sent last time I believe did not create any PDFs, it just launched a little testing screen and occasionally launched Distiller, but I don't recall if it was every time.

    I'll get back to you soon after I've given it a try. Thanks again for all your help.
     
  11. kryten2, Jun 7, 2012
    Last edited: Jun 9, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #11
    Thank you for your feedback. I'll fire up my other ahum Mac with Snow Leopard to make a screenrecording of a working folder action with Acrobat Distiller.
     

    Attached Files:

Share This Page