• 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
Opening the newest file in a folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Opening the newest file in a folder


  • Subject: Opening the newest file in a folder
  • From: Craig Cope <email@hidden>
  • Date: Fri, 14 Dec 2007 12:12:51 -0600

I need to open any file most recently dropped into a folder so I can do some text manipulation on it.  My script does the necessary manipulation on a file if I supply its precise file name, but, in practice, the name will vary.  My attempts to get the script to open the most recent file have failed (The folder event to launch the script may not work either, but that's probably off topic).  Can anyone suggest how I might do that.  I'll attach half a dozen attempts, I made.  Maybe you can use them as a starting point or point out why they fail.

Regard, CC

tell application "Finder"
--this fails: set vNewestFileName to (item 1 of (sort every file of myFolder by modification date))
--this fails: set vNewestFileName to item 1 of (every item of folder myFolder sort by modification date)
(*this fails: set vFileList to (sort files of myFolder by modification date)
set vNewestFileName to (contents of item 1 of vFileList)*)
(*this fails: set vFileList to every file of folder myFolder sort by modification date
set vNewestFile to item 1 of vFileList as alias*)
(*fails: open myFolder
set view of myFolder to modification date
set vNewestFile to item 1 of myFolder as alias*)
(*fails: set vNumItems to count of items in myFolder
if vNumItems is not 1 then
set vFileList to every file in folder myFolder
else
set vFileList to {every file in myFolder as alias}
end if
set vLatestFile to modification date of item 1 in vFileList
set vNewestFile to file name of item 1 in vFileList
repeat with vItem in vFileList
if modification date of vItem > vLatestFile then
set vLatestFile to modification date of vItem
set vNewestFile to file name of vItem
end if
end repeat*)



end tell
 _______________________________________________
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: Opening the newest file in a folder
      • From: Doug McNutt <email@hidden>
  • Prev by Date: Re: Excel 2004
  • Next by Date: Re: FileMaker 6 "not scriptable" under Leopard?
  • Previous by thread: Re: Permissions Question
  • Next by thread: Re: Opening the newest file in a folder
  • Index(es):
    • Date
    • Thread