I am trying to use Folder Actions to open a new image that is deposited into a folder using Preview. It seems relatively simple but my script does not work, so your help is appreciated.
on adding folder items to this_folder after receiving these_items
tell application "Finder"
open file this_item using application "Preview"
end tell
end adding folder items to
In your script, this_item is never defined. Usually you would wrap your code in a loop like repeat with this_item in these_items, but that is not needed if all you want to do is open the files with Preview:
on adding folder items to this_folder after receiving these_items
tell application "Preview" to open these_items
end adding folder items to
Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)
What exactly do you mean by “the latest image”? In the script above, these_items will be a list of items that were just added to the folder (moved, copied, dropped, created, etc.). In this sense they are all equally new to the folder.
Or do you mean that you want to determine a single file that has the most recent modification time (technically (since modifications times might be in the future for one reason or another) a file that has a modification time that is furthest from the epoch)? If so you could see some odd behavior from the script. You could arrange things so that the file with the most recent modification time was always opened even if it was not one of the files that was just added to the folder (i.e. a file with an old modification date was moved into the folder). But that seems like it would be confusing: “I dropped these four files on the folder, but then it opened some completely different file from the folder!”.
Or do you want o determine the most recently modified file of those that were just added to the folder?