• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: last modified file - how to catch?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: last modified file - how to catch?


  • Subject: Re: last modified file - how to catch?
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 06 Jul 2014 19:09:49 -0500

On Jul 06, 2014, at 16:07, okn <email@hidden> wrote:
With AppleScript I know how to get the first or last file in a folder, f ex:
______________________________________________________________________

Hey Omar

get first file of folder alias "MacHD:Users:okn:Documents:_Output:”

You don't need folder in this context.

But I need the last file (by property?!) Modification date.

Also maybe one should first set the folder window to sort by Modification date, so that the latest file to have been added to the folder _Output would be uppermost?!

---------------------------------------------------
set _fldr to (path to downloads folder)

tell application "Finder"
first file of _fldr as alias
end tell
---------------------------------------------------

Note as alias.  This is always faster than returning a Finder-reference.

Note too that if you run this, change the sort in the Finder window, and run it again that the item found will NOT change.

One way to do this is using the Finder:

---------------------------------------------------
set _fldr to path to downloads folder

tell application "Finder"
set lastFile to (last item of (sort files of _fldr by modification date)) as alias
end tell
---------------------------------------------------

The pitfall is that this can be very slow on pre-Mavericks systems (Mavericks seems to have made some improvement, but it's still not instant).

A faster method is:

-------------------------------------------------------------------------------------------
set _path to POSIX path of (path to downloads folder as text)
set lastModifiedFile to first paragraph of (do shell script "ls -Ft " & quoted form of _path & " | sed -E '/\\/$/d'")
-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: last modified file - how to catch?
      • From: Shane Stanley <email@hidden>
References: 
 >last modified file - how to catch? (From: okn <email@hidden>)

  • Prev by Date: last modified file - how to catch?
  • Next by Date: Re: last modified file - how to catch?
  • Previous by thread: last modified file - how to catch?
  • Next by thread: Re: last modified file - how to catch?
  • Index(es):
    • Date
    • Thread