• 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: "info for"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "info for"


  • Subject: Re: "info for"
  • From: has <email@hidden>
  • Date: Tue, 28 May 2002 16:48:16 +0100

David Crowe wrote:

>I'd like to thank Timothy Bates for helping me with "info for". It
>looks like my problem was how to handle Finder lists properly.

There's a mixture of entertaining issues afoot here.

--

The first issue is how the 'get selection' command you give the Finder
works. The Finder's selection property always contains a _list_ of file
references (even if only one file is selected). e.g. Try:

tell application "Finder"
set theSelection to the selection
end tell
--> returns a list

The Standard Additions 'info for' command _can't_ take a list of file refs
however, only a single file reference. If you pass it a list containing
only a single file reference, you'll get lucky as AS is smart enough to
coerce single-item lists when needed. But if you pass it a list containing
<> 1 items, it'll fail. So your best solution, as Tim shows, is to use a
repeat loop to iterate across the list, sending each item [i.e. each file
ref] to 'info for' one at a time.

--

The second issue is how a Finder file reference differs to file references
everywhere else in AppleScript. Because the Finder's job is file
manipulation and management, it has a whole bunch of extra features for
dealing with the file system, including its own method of referring to
files and folders as objects within other objects, eg:

(file "letter") of (folder "work") of (disk "foo")

[I've added parentheses here to emphasise each object.]

Since file [1], folder and disk objects are something known only to the
Finder, you cannot use these terms outside a Finder tell block. You may
also run into problems if you take a Finder file reference [object x of
object y of object z] and then try to use it _outside_ a Finder tell block.

In this situation, the safe bet is to turn the Finder file reference into
an alias, which is a concept understood by AppleScript itself (and thus by
anyone):

FinderFileRef as alias
--> (alias "foo:work:letter")

As Tim says, the Finder has a built in way of turning a list of Finder file
references into a list of aliases, but it's kinda broke. [Fortunately he
also provides the workaround.]

--

The last issue is: when do you actually need to use 'info for'? The answer
is: only when you're working with outside the Finder with aliases. As long
as you're working with Finder file references, you can get information like
name, date modified, etc from the object itself. Every file/folder/disk
object contains a number of properties, the values of which you can get and
[sometimes] set:

======================================================================

tell application "Finder"
set theSelection to the selection

repeat with anItem in theSelection
display dialog "Name: " & name of anItem
end repeat

end tell

======================================================================


To work out what all the properties of a file object are takes a bit of
detective work in the dreaded Finder dictionary (a vast and cryptic maze,
and probable graveyard of many an aspiring young scripter).

First, if you buzz down the entries to "Class file", as this is the class
from which file objects are born. This tells you a few - but not all - of
the properties you can find in a file object:

Class file : (inherits from item) A file
Properties:
file type
creator type
locked
stationery
product version
version


Hmmm, doesn't look like much at this point. But notice the sly, almost
invisible "inherits from item" phrase. This means that in addition to the
properties shown here, file objects also contain all the properties listed
under the 'item' class. So if you buzz back up the page to "Class item",
you can get a list of all the other properties you will find in a file
object:

Class item : An item
Properties:
name
index
id
container
disk
folder
[etc, etc, etc...]


Incredibly useful information - once you've worked out how to read it! But
once armed with that understanding, you can now you can do stuff like:

======================================================================

on DisplayInfo(fileName, fileSize, creationDate, fileType)
display dialog "Name: " & fileName & "
Size: " & fileSize & "
Creation date: " & creationDate & "
File type: " & fileType
end DisplayInfo

tell application "Finder"
set theSelection to the selection

repeat with anItem in theSelection
set fileName to name of anItem
set fileSize to size of anItem
set creationDate to creation date of anItem
set fileType to file type of anItem

my DisplayInfo(fileName, fileSize, creationDate, fileType)
end repeat

end tell

======================================================================


HTH

has

[1] In fact, the term 'file' does have its own meaning outside the Finder,
but it's different to the Finder's understanding, hence even more room for
confusion.:p

--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Saving lists of records to a text file
  • Next by Date: Telling a list of apps to activate?
  • Previous by thread: Re: "info for"
  • Next by thread: Saving lists of records to a text file
  • Index(es):
    • Date
    • Thread