• 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: Omar K N <email@hidden>
  • Date: Mon, 07 Jul 2014 23:34:42 +0200


Hi & good day,

What I don’t understand is that when I use Chris’ shell script I can’t open the last file:
--------------------------------..————————————————
trying to open file with TextEdit:

set _path to "/Users/okn/Documents/_Output"
set lastModifiedFile to first paragraph of (do shell script "ls -Ft " & quoted form of _path & " | sed -E '/\\/$/d'")
get lastModifiedFile
tell application "TextEdit"
open lastModifiedFile
end tell
—> file does not exist!
--------------------------------..———————————————— 
trying to open file with Finder:


set _path to "/Users/okn/Documents/_Output"
set lastModifiedFile to first paragraph of (do shell script "ls -Ft " & quoted form of _path & " | sed -E '/\\/$/d'")
get lastModifiedFile
tell application "Finder"
open lastModifiedFile
end tell
--> Finder error: Handler can't handle objects of this class.
--------------------------------..————————————————


but it works here:

tell application "Finder"
set _fldr to folder "MacHD:Users:okn:Documents:_Output"
set lastFile to (last item of (sort files of _fldr by modification date)) of alias
end tell
# Thomas Fischer, 07 Jul 2014 18:11, mE
tell application "Finder"
open lastFile
end tell
--> works fine, opens the lastFile

Why would AS treat the open cmd so different, ok it’s not a file, just a variable of a path?!

/
with best regards,
Omar K N
Stockholm, Sweden






On 07 Jul 2014, at 21:00, email@hidden wrote:

Message: 2
Date: Mon, 07 Jul 2014 18:11:39 +0200
From: Thomas Fischer <email@hidden>
To: AS users <email@hidden>
Subject: Re: last modified file - how to catch?
Message-ID: <email@hidden" style="font-family: LucidaGrande; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">email@hidden>
Content-Type: text/plain; charset="windows-1252"

Hello Omar,

the objects in AppleScript are unfriendly beasts that cannot easily be carried from one application (like the Finder) to another (like TextEdit).
I can't go deeply into this right now, but
path to folder "_Output" of folder "Documents" of home as text)
is formally a Finder path, but "home" is not defined (on my machine, OS X 10.6.8)
Better to start with
choose folder
to get an alias and feed that into the rest of the script.  
Similarly with
set _fldr to folder "MacHD:Users:okn:Documents:_Output"


This won't give you a Finder folder, actually it is just a string, but some applications are willing to take it as a proxy for a folder. Finder won't.
But you can do this:

tell application "Finder"
set _fldr to folder "MacHD:Users:okn:Documents:_Output"
set lastFile to (last item of (sort files of _fldr by modification date)) of alias
# get lastFile  # not necessary
end tell

You'll see Finder's version of a file if you omit the "of alias" above.
The alias is acceptable to other applications, the Finder version usually not.

 _______________________________________________
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: Christopher Stone <email@hidden>
  • Prev by Date: Re: last modified file - how to catch?
  • Next by Date: A Syntax Question
  • Previous by thread: last modified file - how to catch?
  • Next by thread: Re: last modified file - how to catch?
  • Index(es):
    • Date
    • Thread