Need a folder script - willint to pay

Folder Script

I’m looking for someone to write a folder script for Mac OSX.
A little explanation, we are running several Epson printers with lot of volume from students in our photography program. We use Colorbyte Imageprint & a feature of the application called autoprint. Autoprint looks at a hotfolder and processes the image files based on setting I’ve outlined. This works fairly well but there are some problems and some things that autoprint can’t do for us and I though a folder script might solve the problems. I’m looking for a script that pre-filters the files before going into the hot-folder.

We are running the Imageprint application on a dual processor G5 Mac and will be shortly using Tiger Server Software on the Mac.

Here’s what I’d like the script to do.

When a file is dropped into a specified folder

  1. The file is renamed using the user name (of the user who deposited the file in the folder) plus the date and time.
    The file name might look something like this
    jmagil-epson4000-050805-1641.jpg
  2. !!!BONUS FEATURE!!! If the image files dimensions can be extracted and added to the file name!!!
  3. !!!BONUS FEATURE #2!!! If a user drops more than one file at a time in the folder all that users files are moved to a different specified folder.
  4. Permissions for the file are set to Read Write for everyone
  5. If the file isn’t a jpeg it is move into a specified folder/if the file is a jpeg it is move to a different specified folder

We are basically trying to manage our student printing and bill the students based on the printing volume.

Browser: Safari 312
Operating System: Mac OS X (10.3.7)

Try this.

-- edit these paths to represent where you want JPEG and non-JPEG files to go
property JPEGFolder : "/path/to/jpegs/"
property nonJPEGFolder : "/path/to/non/jpegs/"

-- Folder Action handler to automatically run the script
-- when new items are dropped in the folder
on adding folder items to theFolder after receiving theAddedItems
	
	repeat with eachItem in theAddedItems
		my doit(eachItem)
	end repeat
	
end adding folder items to

-- run handler, called if you jusst run the script
-- asks for a file and processes that in the same way.
on run
	set theFile to choose file
	doit(theFile)
end run


-- main handler that does all the work
on doit(thisFile)
	set thisFilePath to POSIX path of thisFile
	set fileinfo to info for thisFile
	if name extension of fileinfo is in {"jpg", "jpeg"} or file type of fileinfo is "JPEG" then
		-- we have a jpeg
		set imageSize to getImageDims(thisFile)
		set dateStr to getCurrentDate()
		set username to getUserName(thisFile)
		set newfilename to username & "-" & dateStr & "-" & imageSize & "." & name extension of fileinfo
		do shell script "mv " & quoted form of thisFilePath & space & quoted form of (JPEGFolder & newfilename)
	else
		-- it's not a JPEG, so move it
		do shell script "mv " & quoted form of thisFilePath & space & nonJPEGFolder
	end if
end doit


-- username handler
on getUserName(theFile)
	-- there's no way to find the name of the user that dropped the file
	-- the best you can do is find the file's owner, which should be sufficient
	set filepath to POSIX path of theFile
	set username to do shell script "ls -l " & quoted form of filepath & " | awk '{print $3}'"
	return username
end getUserName

-- date string handler
-- adjust as necessary if you don't like the date format
on getCurrentDate()
	set dateStr to do shell script "date +%m%d%y-%H%M"
	return dateStr
end getCurrentDate

-- Image Events handler to get the dimensions of an image
on getImageDims(theImageFile)
	set imageSizeStr to ""
	-- use a try block in case it's not an image file
	--	try
	tell application "Image Events"
		set myImage to open theImageFile
		set imageDims to dimensions of myImage
		set imageSizeStr to (item 1 of imageDims as integer) & "x" & (item 2 of imageDims as integer) as text
	end tell
	--	end try
	return imageSizeStr
end getImageDims

About the only thing my script doesn’t do that you asked for is the “If a user drops more than one file at a time in the folder all that users files are moved to a different specified folder”. I’m not entirely sure what you mean by that since you separately ask that JPEGs go one way while non-JPEGs go the other. You can’t have it both ways :slight_smile:

Browser: Safari 412
Operating System: Mac OS X (10.3.7)

I attached the script to the folder and enabled it and it didn’t seem to work. Then I ran the script on a file and it gave me an applescript error “The variable myImage is not defined.” I tried removing all references to the dimensions and it did successfully move the files and rename them with user name, date and time.

Is there something missing that isn’t defining the variable myImage?

Thanks for the help

Browser: Safari 312
Operating System: Mac OS X (10.3.7)

Oh,

The group of files thing. Don’t know if that could come at the beginning and stop further moves. The reason for it is to prevent any single student from simply dropping 20 files in the folder and going home. Our rule is you send one print and evaluate the results before sending another. Since it takes about 7-10 minutes to print an image if some one drops 20 images in it may be an hour or so before people who are following the correct procedure see one of their prints.

Thanks Again

Browser: Safari 312
Operating System: Mac OS X (10.3.7)

The only thing I can think of that would do this would be if the file was in a format that Image Events couldn’t read. Are you sure it was a valid JPEG file?

Currently, the script as written will process all image files. To just process the first and drop the rest change the ‘on adding files to…’ so that:

on adding folder items to theFolder after receiving theAddedItems
   my doit(item 1 of theAddedItems)
   if count theAddedItems > 1 then
     repeat with extraFile in (items 2 through end of theAddedItems)
       do shell script "mv " & quoted form of POSIX path of extraFile & "/path/to/not/processed/"
      end repeat
   end if
end adding folder items to

Browser: Safari 412
Operating System: Mac OS X (10.3.7)