Process a folder at a given time???

Hello-
I have a script that is used as a droplet right now. It basically batch processes illustrator files and resaves them as another file type in a folder the user selects.

I am writting as I am curious if there is a way to attach a folder action the folder all the ai files are in and everyday at a given time the script runs and checks the files modified date and if that date is later than the last time the script ran it would batch process those files and send the new file type in a specific place, ie a server location or folder. This would mean you would not have to ever manually batch process the files, no more dragging to the icon or running the script on chosen files. This script would simply chack your files and if the date correct it processes that file.

Sounds simple hun? I have been trying but I cannot get past even trying to get a script to run once an ai file is dropped on the folder. Any help with the problem would be great. thanks

:cool: mamba

hi mamba,

you should check into the ‘Cron’ facility of OS X. here is a good place to start:

http://www.macosxhints.com/article.php?story=2001020700163714

also mentioned in the article’s comments is ‘Cronnix’ a GUI front end that makes setting up a cron job really easy.

you’ll want to use an ‘osascript’ command to start your AppleScript. my best advice would be to adapt your current script so that it works when you double click it, then use cron to call ‘/usr/bin/osascript -e /path/to/my/AppleScript’. you can set a cronjob to run every hour, once a day, every 5 minutes, once a month, or whatever. it’s pretty flexible.

thanks, but that is way over my head. I could not understand.
I know this can be done with applescript as I have seen it done before, anyone with any ideas on how to write the script or a place to get started with wrting this type of script, I would really appreciate it.
thanks again.

:cool: mamba

hi mamba,

oh well. you should post your code so someone can help change it to double clickable instead of a droplet.

then we can talk about ‘Cronnix’.

hi

actually it is both a droplet and double clickable…


on open theFiles
	processfiles(theFiles)
end open
--if dropped then this is skipped
on run
	choose file with prompt "Hold cmd or shift for Multiple Selections" with multiple selections allowed without invisibles
	processfiles(result)
end run

on processfiles(theFiles)
	--choose where to save your eps files
	set theChoice to choose folder with prompt "Choose eps file destination." without invisibles
	set choicePath to theChoice as string
	--create a list of the files you are going to process
	set theFiles to theFiles as list
	repeat with aFile in theFiles
		set aFile to aFile as alias
		set dropPath to choicePath
		set dupNames to {}
		set moveToPath to dropPath
		set modTime to (current date) as string
		
		--open illustrator and begin conversion
		tell application "Illustrator CS"
			activate
			set user interaction level to never interact

<<CODE FOR PROCESS IS HERE>>

		end tell
	end repeat
	
end processfiles


any help? thanks y’all…

:cool: mamba

Just to throw in my 2 cents, the new “cron” in 10.4+ is actually “launchd” - unfortunately - for the novice user it’s probably too much. That said - you can use iCal to schedule timed events - you may want to look into that. That works for simple things like what you want to do usually pretty well.

Why would I need to use ical to script in an event??? Why can I not just use the system time? I know how to call upon that time. There has to be a way to write a script that is attached to a folder and everyday runs and checks all the files in said folder for their modified date and if that date is after the last time the script ran it runs the process part of the srcipt on said files. anyone? ideas? help?

thanks for trying everyone…

:cool: mamba

Because it is an easy way to schedule processes and events :wink:

I’m afraid there isn’t: folder action scripts won’t do anything until they are triggered by the folder event that was defined in the script. If you don’t like Cronnix or iCal you can write an AppleScript application which stays open in the background. Using the on idle … end idle routine you check the current date and time and trigger whatever you need. But as there are simplier ways to do this (Cronnix, iCal) I think this is kind of waste of resources.

Good scripting
Farid

could you give me an example of the ical script that would run the folder script?
thanks…

:cool: mamba

I SOLVED IT!!!

So I simply did a folder action that checks all the modification dates of the files in said folder, if the date is less than today’s date it processes the file. Only problem is how to get this action to run everyday? Only want it to run once a day, any suggestions??? Any help would be great, here is my code so far…


set myFolder to choose folder --WILL BE ATTACHED TO A FOLDER THIS IS JUST FOR TESTING
set theChoice to "path to folder:"
set choicePath to theChoice as string

set date_stamp to ((current date))
tell application "Finder"
	set theFiles to every file of myFolder whose modification date is less than date_stamp

	set theFiles to theFiles as list
	repeat with aFile in theFiles
		set aFile to aFile as alias
		set dropPath to choicePath
		set dupNames to {}
		set moveToPath to dropPath
		set modTime to (current date) as string
	end repeat
end tell

--open illustrator and begin eps conversion
tell application "Illustrator CS"
	activate
	set user interaction level to never interact --turns off the majority of dialogs
	
	set theImage to open aFile --open and process one of the files
	set thisDoc to current document

:cool: mamba

Mamba - I don’t think you are understanding what we are saying about iCal - it’s simple - just open iCal and create a reacurring, daily, “meeting” - and then under Alarm - choose “run Script” and then navigate to your script file.

That’s it - your done - the script you created will run every day - at that time.

What you’re not understanding is that the script needs something to tell it when to run, iCal is that mechanism in this case. I persoanlly use launchd - but since you don’t want to get into that level of understanding with the system - iCal -or an idle event are your best bets.