How to make a FolderAction from a Script?

Hello, I am absolute New in things AppleScript!

I try to write a Script, which contol a desktop folder and print the pdf`s from the folder with Acrobat 6.0 Professional.
Who can help me to create a folder-action from my script!
I thank you very much in advance!

mikelchris

property InOrdner : "MacOS X:Users:michael:Desktop:pdf:"
property DoneOrdner : "MacOS X:Users:michael:Desktop:ausgabe:"

on Printjob(Datei)
	tell application "Acrobat 6.0 Professional"
		open Datei
		print pages front document with shrink to fit
		close front document
	end tell
end Printjob


tell application "Finder"
	set dateiliste to every file of folder InOrdner
end tell
if length of dateiliste > 0 then
	repeat with i from 1 to length of dateiliste
		Printjob(item i of dateiliste)
		tell application "Finder"
			move item i of dateiliste to folder DoneOrdner
		end tell
	end repeat
end if

on adding folder items to theFolder after receiving theFiles
repeat with theFile in theFiles
– print it
end repeat
end adding folder items to

Stick your script in /Library/Scripts/Folder Action Scripts/

Control-click the folder in question and see the folder action items in the contextul menu – enable and configure to attach your script to the folder.

Hi,
my folder-action works now! :slight_smile:
But i have another problem now .

When a filename already exists in the “DoneFolder” - i would like to rename the new pdf in “xxxxx-new.pdf”

How can i do that?

Many thanks for your help!

property type_list : {"pdf"}
property extension_list : {"pdf"}
property DoneOrdner : "MacOS X:Users:michael:Desktop:ausgabe:"

on adding folder items to this_folder after receiving these_items
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to the info for this_item
		if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			
			-- datei öffnen und drucken 
			tell application "Acrobat 6.0 Professional"
				open this_item
				print pages front document with shrink to fit
				close front document
				
				-- datei in ausgabeordner verschieben
				tell application "Finder"
					move this_item to folder DoneOrdner
				end tell
				
			end tell
		end if
		
	end repeat
end adding folder items to

This will require Jon’s Commands OSAX. I consider Jon’s Commands most useful!!
Look at the “copyFile” & “deleteFile” commands below. The stuff in the Finder tell block does what you want (I think), allowing for up to 1000 incarnations. Download Jon’s OSAX and there ya go!


property type_list : {"pdf"}
property extension_list : {"pdf"}
property DoneOrdner : "MacOS X:Users:michael:Desktop:ausgabe:"

on adding folder items to this_folder after receiving these_items
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to the info for this_item
		if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
			
			-- datei öffnen und drucken 
			tell application "Acrobat 6.0.2 Professional"
				open this_item
				print pages front document with shrink to fit
				close front document
				
				-- datei in ausgabeordner verschieben 
				tell application "Finder"
					--move this_item to folder DoneOrdner 
					

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	(*
This will auto-incerment a file name on a move to a new folder and a series previous files may exist. It allows for up to 1000 pre-existing file names
Requires: Jon's Commands OSAX
*)
	
	--set this_item to "OSX:Users:ByteJockey:Desktop:inausgabe:MyFile.pdf"
	set AppleScript's text item delimiters to ":"
	set this_item_fullname to text item -1 of (this_item as string)
	set AppleScript's text item delimiters to "."
	set this_item_root to text item 1 of this_item_fullname
	set this_item_extension to text item -1 of this_item_fullname
	set AppleScript's text item delimiters to ""
	
	set the item_info to the info for this_item
	if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
		if file (done_folder & this_item_fullname) exists then
			set NameGood to false
			set x to 0
			repeat until NameGood is true
				set x to x + 1
				set xx to x
				if xx < 10 then
					set xx to "00" & x
				else
					if xx < 100 then set xx to "0" & x
				end if
				if file (done_folder & this_item_root & "_" & xx & "." & this_item_extension) exists then
				else
					set NameGood to true
				end if
			end repeat
			copyFile this_item to (done_folder & this_item_root & "_" & xx & "." & this_item_extension) as string with replacing
			repeat until file ((done_folder & this_item_root & "_" & xx & "." & this_item_extension) as string) exists
				delay 5
			end repeat
			deleteFile this_item
		else
			copyFile this_item to (done_folder & this_item_fullname) as string with replacing
			repeat until file ((done_folder & this_item_fullname) as string) exists
				delay 5
			end repeat
			deleteFile this_item
		end if
	end if
end tell
--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


				end tell
				
			end tell
		end if
		
	end repeat
end adding folder items to

I hope it helps.
Lemeeno

Jeff

Anything is wrong with my script!
The files are not move to the “DoneOrdner”.

Please help me!
Many thanks…

property type_list : {"pdf"} 
property extension_list : {"pdf"} 
property DoneOrdner : "MacOS X:Users:michael:Desktop:ausgabe:" 

on adding folder items to this_folder after receiving these_items 
   repeat with i from 1 to number of items in these_items 
      set this_item to item i of these_items 
      set the item_info to the info for this_item 
      if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then 
          
         -- datei öffnen und drucken 
         tell application "Acrobat 6.0.1 Professional" 
            open this_item 
            print pages front document with shrink to fit 
            close front document 
             
            -- datei in ausgabeordner verschieben 
            tell application "Finder" 
               --move this_item to folder DoneOrdner 
                
                
               -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
               -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
               (* 
This will auto-incerment a file name on a move to a new folder and a series previous files may exist. It allows for up to 1000 pre-existing file names 
Requires: Jon's Commands OSAX 
*) 
                
               --set this_item to "OSX:Users:ByteJockey:Desktop:inausgabe:MyFile.pdf" 
               set AppleScript's text item delimiters to ":" 
               set this_item_fullname to text item -1 of (this_item as string) 
               set AppleScript's text item delimiters to "." 
               set this_item_root to text item 1 of this_item_fullname 
               set this_item_extension to text item -1 of this_item_fullname 
               set AppleScript's text item delimiters to "" 
                
               set the item_info to the info for this_item 
               if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then 
                  if file (DoneOrdner & this_item_fullname) exists then 
                     set NameGood to false 
                     set x to 0 
                     repeat until NameGood is true 
                        set x to x + 1 
                        set xx to x 
                        if xx < 10 then 
                           set xx to "00" & x 
                        else 
                           if xx < 100 then set xx to "0" & x 
                        end if 
                        if file (DoneOrdner & this_item_root & "_" & xx & "." & this_item_extension) exists then 
                        else 
                           set NameGood to true 
                        end if 
                     end repeat 
                     copyFile this_item to (DoneOrdner & this_item_root & "_" & xx & "." & this_item_extension) as string with replacing 
                     repeat until file ((DoneOrdner & this_item_root & "_" & xx & "." & this_item_extension) as string) exists 
                        delay 5 
                     end repeat 
                     deleteFile this_item 
                  else 
                     copyFile this_item to (DoneOrdner & this_item_fullname) as string with replacing 
                     repeat until file ((DoneOrdner & this_item_fullname) as string) exists 
                        delay 5 
                     end repeat 
                     deleteFile this_item 
                  end if 
               end if 
            end tell 
            --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
            --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
             
             
         end tell 
      end if 
   end repeat 
end adding folder items to