Motion Designer (Non-programer) looking for applescript help.

Hi everyone - I’m a motion graphics designer trying to make my life easier. I’d like to make a program (applescript) that will monitor our render farm and notify us when projects have finished. I’ve been poking around with applescript but have never used it and have no idea of how to start. What I’m hoping to find is someone who can work with me on making this thing come to life, maybe someone out there that knows this stuff and has some spare time (Like any of us have spare time). :wink:

Here is a breif scenario:
-Designers will be responsible for starting this monitoring program.
-Designers will designate which directory to watch (Via dialog box?)
-Program monitors the main directory, going through all of the subdirectories, and moves finished projects to a new directory. (there is a text file that the program needs to read in order for it to find out if the project is done.)
-Once old projects are moved the program will email the designer that it’s done.

That’s it. This might be more complex then I think it is. From my point of view this shouldn’t be difficult but what do I know.

Model: Power PC G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi eyekree8,

Sounds like a interesting little project you have in front of yourself. Are you looking to have this developed for you by a consultant? If so you should make a entry over at MacDeveloper

If your looking to do the work, I would suggest starting in small steps and then worry about putting them all together to make the entire project work. So if your case is the later, show us what you have so far and we can help guide you to where you want to end up =)

I thought about the points you made before I posted and came up with these thoughts.

Consultant: Pros - A consultant would be great. In general I could tell them what I want and they would come back to me with a finished product. This would save me a lot of time and all I would have to do is some project management.
Cons - Not having any involvement would leave me with a tool that I wouldn’t feel comfortable messing with… modifying. I’m almost positive that this tool will need to grow and evolve to meet our needs and I’d like to be able to make that happen myself.

Make it my self: Pros - Doing it my self would give me a great way to learn applescript and hopefully a starting point for the other ideas I have.
Cons - I wanted to go this route but as I started to get into it I found that I had no idea of what was going on. Lost = frustration and with the limited amount of time I have to devote to this I’m afraid I’d start it and then soon put it on the back burner to be forgotten.

So with those thoughts I figured maybe finding a middle road would be good. Work closely with someone, explain the functionality and add what little I have to the game. Help out where I can and do some of the work (maybe after some schooling).

I like your suggestion of posting what I have and having the forum help guide me in the right direction but all I have is a script that can send me an email. I’ve spent a couple of days looking around the internet for examples of what I’m trying to do, going over the online resources at apple.com and have only come up with one bit of information that’s pertinent to this project. I think my problem is how I’m attacking this. I’m a designer and use a certain logic when attacking a project. I don’t have a programmers head so my method of attack is probably all backwards.

The more I think about it the more it looks like I need a tutor. :slight_smile:

Hi eyekree8;

Does the “watcher” have to monitor the contents of a text file and when it changes (by getting larger or longer, for example), then read the text file, move files it finds there (if found in the folder), and finally amend the list,

OR,

Does the watcher have to monitor the folder for new files as they appear from time to time, and do something with them (like add them to the list or move them if they are found on the list)? Both are fairly straight-forward, but nowhere near the same.

Hi Adam - All of the projects we render get dumped to a directory on the server called “Watch Folder”. A directory for each project is created so we’d could get something like:

/Watch Folder/project1/
/Watch Folder/project2/
/Watch Folder/project3/
/Watch Folder/project4/

In each project directory there is a text file called project1_RCF.txt. What would need to happen is the program would go into the “Watch Folder” and scan the project directories for the *_RCF.txt file. With in this text file there is a bit of text that indicated weather the project in “In Progress” or “Finished” and it could be listed more then once. The reason is that each project can have multiple files set up to render. The list in the text file could look like this:

item1=(User Stopped,1,1,0)
item2=(Finished,1,1,0)
item3=(Queued,1,0,0)
item4=(Queued,1,0,0)
item6=(Queued,1,0,0)

If all are finished I’d like the program to move the project directory to a new location, like “/finishedProjects/” and send an email to the address listed in the RCF.txt file.

That’s the basic functionality. There may be some other things that may impact this but this should give you an idea of what’s going on.

Thanks

Given that you want to learn how to do this yourself (which I applaud :wink: ), this is one possible framework for accomplishing what you want to do - it’s not ready to run; it’s just a compilable example whose pieces work.


property tWatchFiles : missing value -- properties "keep" from run to run
property tProjects : missing value

on run -- this runs when the application is started
	set WatchedFolder to (choose folder) as alias
	checkFiles(WatchedFolder)
end run

on idle -- idle scripts are saved as stay-open AppleScript applications and cycle periodically.
	checkFiles(WatchedFolder)
end idle

to checkFiles(wF)
	set pFiles to {}
	tell application "Finder"
		set tProjects to folders of wF as alias list
		repeat with aFolder in tProjects
			set pf to files in aFolder as alias list
			repeat with af in pf
				if name of af contains "_RCF.txt" then set end of pFiles to contents of af
			end repeat
		end repeat
	end tell
	repeat with RCF in pFiles
		set thisList to read RCF
		set astid to AppleScript's text item delimiters
		set text item delimiters to "(Finished"
		set TI to text items of tList
		set text item delimiters to ""
		set Fin to first word of last paragraph of first item of TI --> "item2"
		-- but as set up only gets the first one. This is just to illustrate how you get one.
		my DoStuff(Fin)
	end repeat
end checkFiles

to DoStuff(someRef)
	-- press on with stuff
end DoStuff

Adam, this is great! Thanks for the help. So let me see if I get this. (I hope I’m not being to annoying :slight_smile: )

Here you are setting up the variables.
property tWatchFiles : missing value – properties “keep” from run to run
property tProjects : missing value

when the program runs it’s directed to a specific folder and is told to think of the folder as “checkFiles(WatchedFolder)”. I’m not sure why you would want to change its identity though. If you know the name of the folder, why change it?
on run – this runs when the application is started
set WatchedFolder to (choose folder) as alias
checkFiles(WatchedFolder)
end run

maybe my previous thought was wrong. This statement looks like “checkFiles” is a function. As the program idles it constantly checks the “Watchedfolder”. So now I’m a bit confused about the “as alias” bit. I’ll try to look that up.
on idle – idle scripts are saved as stay-open AppleScript applications and cycle periodically.
checkFiles(WatchedFolder)
end idle

the function “checkFiles”
to checkFiles(wF) -Don’t know what the (wF) is for
set pFiles to {} -Don’t know what this line is for

this makes sence. get the contents of the “WatchFolder” and make a list of it to use later.
tell application “Finder”
set tProjects to folders of WatchedFolder as alias list

If you have made the list why would you need the repeat? And why the “aFolder”? Are we trying to make a list of the contents of any folder nested within each project folder?
repeat with aFolder in tProjects
set pf to files in aFolder as alias list

Is the repeat going one more level deeper?
repeat with af in pf

Here is where my head starts to spin a bit. I understand that it is told to look for files with the “_RCF.txt” in the name. But I’m not sure where this pFiles come from and what it does. did we just create another variable, “pFiles”?
if name of af contains “_RCF.txt” then set end of pFiles to contents of af
end repeat
end repeat
end tell

OK. Head spinning more. We are reading the RCF text files here. We open it up and look for something with “(Finished” in it. Then it starts getting confusing. What is “astid” and this “AppleScript’s text item delimiters”?
repeat with RCF in pFiles
set thisList to read RCF
set astid to AppleScript’s text item delimiters

I think not knowing what the “AppleScript’s text item delimiters” does is confusing me here. Not sure where “TI” and “tList” comes from.
set text item delimiters to “(Finished”

Very confused here.
set TI to text items of tList
set text item delimiters to “”
set Fin to first word of last paragraph of first item of TI → “item2”

Once you have funished checking the text files execute the funtion “DoStuff”.
– but as set up only gets the first one. This is just to illustrate how you get one.
my DoStuff(Fin)
end repeat
end checkFiles

to DoStuff(someRef)
– press on with stuff
end DoStuff

So in my “DoStuff” function, after I have it move the finished project to a new folder, I’ll have it email the designer. I found the following script that seasm to work well.

set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","


set |to| to "scott@flyingspot.com"
set |from| to "scott@flyingspot.com"
set smtpServer to "smtp server here"

--> delete the three following lines if you don't need authentication:
set username to "scott@flyingspot.com"
set |password| to "password here"
set authentication to auto --> or plain, login, crammd5, anonymous

set theSubject to "Applescript test"
set thebody to "This is a test! This is only a test"


--> Now, compose the source and send the email...
set rawSource to "Date: " & (do shell script "date '+%a, %e %b %Y %H:%M:%S %z'") & return & ¬
	"To: <" & |to| & ">" & return & ¬
	"From: <" & |from| & ">" & return & ¬
	"Subject: " & theSubject & return & ¬
	"Mime-Version: 1.0
X-Mailer: XMail
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: quoted-printable" & return & ¬
	thebody

try
	send raw mail to |to| from |from| raw source rawSource SMTP server smtpServer username |username| password |password| authentication |authentication|
on error number -2753 --> you don't need authentication and such variables are undefined...
	send raw mail to |to| from |from| raw source rawSource SMTP server smtpServer
end try
set AppleScript's text item delimiters to oldTID

Looks like pieces are starting to fall into place. Wow a sence of accomplishment. Thanks for the help!

Question addressed in order

1: Correct persistant variables are being created

2&3: Your right checkFiles is a function or handler… as alias is a way of referencing the folder… there are multiple ways of doing so

4: When you call checkFiles your passing it the folder… in the function you can call the item your being passed anything you want. Here Adam is chossing to refer to the WatchedFolder variable as wF. Though within in the function he appears to be referencing “WatchedFolder” not “wF” that would be a typo. pFiles must be set to an empty list here so that it can be referenced elsewhere in the function.

5: n/a

6: Here he is looping through the folders to find a list of the files to check. aFolder is just a variable name created to reference each specific folder within the watched fodler list.

7: now we are looping through the actual files within a specific folder

8: Okay so now we are assembling a list of all the files that have _RCF.txt in the name. pFiles is a list of these names so we can then start to examine each file one at a time. pFiles is not being recreated btw its the one we made earlier in the script.

9: here we are looking at each file and reading its contents… we are setting a variable we created, on the fly, named astid to the value of applescripts text item delimiters… a text item delimiter is a used to tell where a string is broken into substring.

10 & 11: Using the the new text item delimiters its easier to find the string we are looking for

Thanks for the cogent explanation, MC. I corrected the variable in the handler to wF as you pointed out. Good catch - You can tell I didn’t set up all the folders and files required to actually test this, but it is a framework.

What I recommend for eyekree8 is to get an e-copy of Danny Goodman’s AppleScript Handbook and see the relevant sections to follow what’s happening here. It’s a very good beginning and it’s only $15 to download.

Then, take the sample script apart and work with the pieces, asking questions along the way. By the time he’s “Got” it, he’ll be a scripter capable of carrying on. Here’s the table of contents:

Thanks everyone for the help. You all have been very nice to a graphic desinger wannabe scripter. I have a couple of books waiting for me at the library and hope that this little project of mine actually gets finished.

I’m sure I’ll be posting more soon.

Thanks again.

I should prolly read that myself LOL, I’ve yet to read any AS book =)

You’d be better off at your level to read Matt Neuburg’s AppleScript The Definitive Guide, 2nd Edition. It really covers the nuances and shortcomings of the language and has good examples.

Book… what’s a BOOK?!! :lol::lol::lol:

I haven’t read one of those in years…:cool:

LOL it’s actually sitting on my shelf =) And ya don’t have to point out my “noobness” I’m quite familiar with it already :stuck_out_tongue: j/k

Matt really should do audio books though that guy is a riot!!!

I meant that you were an Advanced Noob :smiley:

I started AppleScripting in March of last year, so I’m just a Very Advanced Noob. It’s guys like Kai and Nigel who rank. :stuck_out_tongue:

LOL your too kind, I have much to learn before I would use the word advanced around myself… March of last year? I would have guessed longer than that… do you sleep at all?

To quote Kai, when Nigel Garvey asked the same question of him in a thread some time ago “What, and miss all this fun?”