Applescript automatization?

Hi guys.

First of all, I’m not a programmer. I’m just a photo manager that have a few employees making photos everyday for a lot of newspaper. I tray Automator a few times and realize that Automator not making a good job (it crash’s a lot of times or simply “forget” to repeat the tasks if a new file comes when it still running).

Searching on the net, I find lot of informations about Applescript, but none for my specific problem. And the books are too big to read in a few days and solve the problem before next year (increasing work demand for next year and more employees).

The problem is: We have a lot of photographers sending photos every minute of the day (24/7). Every photographer have they own directory in a specific FTP server and I have to check, constantly, for new photos in this FTP mounted in my Mac as a WebDAV (could be a Dropbox folder too, if became easier). When new photos come, I have to move each photo to a new folder, rename it to photographer name + original file name (like johndoe_dsc_0001.jpg), run a Exiftool command (bash command) to correct some informations and copy to another ftp server (mounted as well) to the web guys make it public. In addiction, generated a log file with the uploaded files and send it by mail to photographers (so they can know what photo is online).

So, what I need to make a better job (could be separated scripts for each folder) is:

  1. On system startup, I mount a WebDAV (I can do this with Automator).
  2. Monitoring the WebDAV folders for new files and move only the jpg files to a temp folder.
  3. Rename the files in temp folder to “folder name_original name”.
  4. Run Exiftool only in this files (the temp folder is just to correct the IPTC Codes with Exiftool).
  5. After corrected with Exiftool, move this files to a backup folder.
  6. Make a copy of new files on backup folder to a mounted ftp server and generated a log file with the uploaded files.
  7. Send this file to photographer (as a confirmation that they photos are online)

It’s possible to make this with Applescript? In Automator I make a new program to each step of the task but, sometimes, they cash.

Any help?

Before I forget:

Lauri Ranta, from StackOverflow, send me this, but doesn’t work (as I’m not a programmer, I don’t know why is not working).

just to note it is NOT easier using SSH to upload photos from Photographers.

FTP or via email is the standard when it comes for photographers to upload the images to an agency or Newspaper.

Most Photographers have and can get their head around FTP clients. Email seriously!. and trying to explain or setup SSH for each of them is beyond a pointless nightmare.

Mark,

In our agency, we use a program that allow us to send photos directly to our FTP server in real-time (or WebDAV server or Dropbox account). Each photographer have his own folder to send and I can mount this server in my Mac as a WebDAV. But all photos came with missing informations and I have to pickup this photos and correct with Exiftool.

I need to pickup all photos of each photographers folders, and rename it to the name of the photographer with the original name (like johndoe_DSC_1234.jpg). This is to known what each photographer do in that day. After that, is just copy to a backup folder and send to the web guys to make it public (and sell, of course).

I can’t see as so difficult to make it work. I make a Automator routine that work a few times, but because a constant crashes and ignore new photos, I can’t trust in Automator anymore.

As I say in the first post, I’m not a programmer. Because of this, I ask for a little help.

In time: Photographers are not computer geeks, I know. But we are not stupid. §:wink:

Well first of all what Lauri send you is a launchd file and a script. The launchd file tell the ‘process manager’ to watch the specified folder and when something changes, a shell command needs to be executed. The shell command is actualy the shell script. What it does is:

  1. Creating a variable for an unique temporary folder
  2. Creating a variable for the webdav folder; It assumes that the webdav is already mounted.
  3. Set the shell options to avoid errors when a folder is empty.
  4. Create the temporary folder
  5. Move, file for file from the webdav folder to the temporary folder
  6. Apply exif command on all moved files.
  7. use a secure (ssh) copy to server user@host:folder/subfolder
  8. move the files from the temporary folder into the current user’s document folder (it’s important which user is running this script)
  9. Remove the (empty) temporary folder.

Because mv will copy and remove over different file systems, as in this case, I would choose to copy the files to the temporary folder at the beginning of the script and remove them at the end. So when something fails halfway the script will retry the run after this.

@DJ Bazzie Wazzie,

Thanks a lot for your explanation about the script and how they work. Now I can study what each command line do and start to think in a solution. Of course, this not make me a beginner programmer (far from it), but give me a good startup.

But, if you allow me, can I ask you for a little more help?

When I run this script, he returns me a lot of error that I figure out is related with the second variable (glob). I presume that something is wrong in this line, because the script can’t see the files inside the folder. Even the subfolder he can’t see. The script only try to find a file named /.jpg.

What I need is a way to watch a lot of jpg files inside some subfolders and get it all, to start the process. And when new files come, start again, and so on. Automator can do this, but I not trust it.

The errors:

Any glue about how to solve it?

And just one more - important - question. What is better to this kind of automatization? Applescript or Shell script?

Thanks a lot for any further help

Peace.

In time:
If I copy all files to temp folder, at the beginning of the process, how could I rename it using the folder name? Remember that I need the final files with a photographer name and original file name (like johndoe_DSC_1234,jpg)?
But I understand and agree with you. If something goes wrong, we don’t loose the photos.

Guys,

After hours digging on the net, I found a lot of good information about shell script (and in portuguese, my natural language). Now I can understand what a few things (like &&, %s and ##*) do and, more important, how to use it.

About the script.

I told yesterday that the script is not working and I can’t understand why. Today I make a few adjustments and now is working “almost” perfectly. I don’t know, yet, how to make a log file with all upload files and send this log by mail, but I’ll continue studying.

So, I change this line

To this

If all photographers only send me jpg files, doesn’t matter filter by type, right?

And in the .plist file, a change this line


To this


I know this is not the final solution, but is working for me. And working very well (at least for now).

But, if I want to make this in Applescript, can I make it work like I need? Without having to include more stings in the .plist file or I’ll have to do this anyway? And Applescript runs like Automator, but faster (can I trust it not crash or forget to watch the subfolders)? Can anyone, point me a direction to make it in Applescript (is not so simple like shell script).

Thanks guys.

Happy holiday for everyone.

Peace.

It’s always good to understand the code, even if you don’t intend to write it for yourself. Then when something went wrong it’s easier to track down the problem.

of course you can, The reason for me with the hold in replies is because it’s weekend. Yesterday I was going out till this morning.

It seems just that the folder “/volumes/WebDAV” doesn’t exists on your machine. You must change the path to an existing path. To collect all image files you could also use the find or mdfind command.

find /Volumes/WebDAV -iname '*.jpg'

or

mdfind -onlyin /Volumes/WebDav 'kMDItemContentType == public.jpeg'

The difference between find and mdfind is that find will actually lookup the file tree for file names that ends with ‘.jpg’ while mdfind will look for files in the spotlight database and not actually search the file system. If the directory you’re searching in is not spotlight enabled it works like find (but find will be quicker then).

Remember that the code will will move all jpg files. Folders and other files, everything that not matches your criteria, will remain on the original place this way and will not be removed from the server.

I can’t give you an really good answer. Both have their pros and cons but in this case it also depends on you strategy. AppleScript is certainly not suitable for creating listeners so this could never be written without help from the system. What I’m saying is that AppleScript is good for one go and then shut it down and restart it in a new process. Basically there are two way to do it:

Write an AppleScript and bind an folder action to it
Write a shell command and bind a trigger to it in launchd

With the last one I can still open an AppleScript using the OSAScript command.

When moving to the temporary folder you can apply the rename immediatly. You can even use an intermediate name when working with those files :smiley:

I’d recommend the last one as the approach more likely to work at all times, since it involves less overhead in that it doesn’t go through System Events and Finder (in opposite order).

On a general basis, there is no better scripting language. Luckily we can choose among a range of scripting languages to solve the problem at hand.