Re: What is wrong with my script
Re: What is wrong with my script
- Subject: Re: What is wrong with my script
- From: Matt Neuburg <email@hidden>
- Date: Fri, 11 Sep 2009 13:45:06 -0700
- Thread-topic: What is wrong with my script
On Fri, 11 Sep 2009 20:53:39 +0200, xorx <email@hidden> said:
>Running the following script in AppleScript editor creates error -1728:
>
>--start
> set AS_path to POSIX file "/Applications/"
> tell application "Finder"
> set dat to modification date of AS_path
> end tell
>--end
>
>It says that "modification date of file "/Applications/"" could not be
>read. This error happens with all possible properties of file objects.
>The file obviously exists and I have no clue why this does not work...
It's pretty simple. A "POSIX file" object doesn't have a modification date
property.
What *does* have a modification date property? Let's look in the Finder's
dictionary.... Aha. An "item" has a modification date property. How do you
specify an item? One way is by its pathname string. Unfortunately the Finder
comes from the deep dark past, and a pathname string means an old-fashioned
Mac pathname string, not a posix path. To convert a posix file to its
old-fashioned Mac pathname string, coerce to a string. So, putting it all
together:
set AS_path to POSIX file "/Applications"
tell application "Finder"
get modification date of item (AS_path as string)
end tell
Another approach is to convert to an alias; that's something the Finder can
deal with:
set AS_path to POSIX file "/Applications"
tell application "Finder"
get modification date of (AS_path as alias)
end tell
There are better ways to come at this; I'm just showing you to come at it
given the initial premise (your first line, and your desire to query the
Finder).
See p. 251 of my book for more about the coercions demonstrated above... m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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