Find Most Recent Image in Folder

Posted on
Sat Jun 16, 2012 4:03 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Find Most Recent Image in Folder

Hey,

I'm setting up a folder action to process an incoming image, from an EyeFi card, to have displayed
on a control page. It works well except I need to modify it to locate the most recent image added
to the folder instead of the file name.

I got it working to process by the name ok but when using different cameras the numbering
is different which throws the script off, hence the need to process by most recent image added.

I think this is the line I can't seem to get right:
set theImage to first item of (every paragraph of (do shell script "ls -t " & EyeFiToProcessFolder)

Code: Select all
on adding folder items to this_folder after receiving added_items
   try
      
      set EyeFiToProcessFolder to (path to desktop as text) & "EyeFi to Process:"
      ---set theOutputFolder to (path to desktop as text) & "EyeFi Images:1.jpg"
      set theOutputFolder to "/Users/TV/Sites/1.jpg"
      
      tell application "Finder"
         
         ---set theImage to last file of folder EyeFiToProcessFolder whose name starts with "D"
         set theImage to first item of (every paragraph of (do shell script "ls -t " & EyeFiToProcessFolder))
         
      end tell
      
      tell application "Image Events"
         launch
         set theImageReference to open file (theImage as text)
         tell theImageReference
            scale it to size 700
            save in theOutputFolder as JPEG
            close
            
            tell application "IndigoServer"
               execute group "EyeFi on Display Screen"
               
            end tell
         end tell
      end tell
      set theFolder to (path to desktop as text) & "EyeFi to Process:"
      set numberOfFiles to count of (paragraphs of (do shell script "mdfind -onlyin " & quoted form of POSIX path of theFolder & " kMDItemFSInvisible == 0"))
      tell application "IndigoServer"
         set the value of variable "EyeFi_Count" to numberOfFiles
      end tell
      
   end try
end adding folder items to


Any help greatly appreciated!

Thanks,

Carl

Posted on
Mon Jun 18, 2012 5:08 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Find Most Recent Image in Folder

Doh,....yet again.

Just needed this bit of code:

tell application "Finder"
sort (get files of sourceFolder) by creation date
-- This raises an error if the folder doesn't contain any files
set theFile to (item 1 of result) as alias
end tell

The ability to take a picture, with any camera loaded with an Eye-Fi card, and have Indigo
display it on our always on display screen has proven to be one of the most popular functions
with all family members.

Thanks,

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 18 guests