[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Folder actions



On 4/19/99 at 3:46 PM, vlb@cfcl.com (Vicki Brown) wrote:

> The answer should be yes... but I am at a loss as to the implementation. It
> probably involves AppleScript :-)

Yup.  Folder Actions are pretty cool despite that.  The only documentation on
them available thus far is in the 8.5 online help, but it's really all you
need.  Launch it from Script Editor's Help menu, or go from the Finder and hit
the little Home icon and start in on AppleScript Help.

Folder Actions are just handlers.  Depending on the syntax you use, they can
fire when an object is added to a folder, removed from a folder, when a folder
is opened, when a folder is closed, or when a folder's window is moved or
resized.  The code they execute is all up to you.

Because they're implemented at the Finder level, folders with Actions attached
have to be open for the Action to fire.  The easiest way around this is to
make the folder in question a pop-up, by dragging its window to the bottom of
the monitor; the Finder will treat it as if it were always open.

This is an quick and dirty example of a proof of concept folder action to open
jpegs, but ignore other kinds of files.  Only the first and last lines make it
a folder action.  Naturally, the stuff in the middle could do anything
(including call a perl script), and it naturally has access to such
interesting tidbits as the attributes of the file or files dropped on it.

  -nat

-------------

on adding folder items to this_folder after receiving added_items

    set my_list to {}

    tell application "Finder"
        repeat with i from 1 to count items of added_items
            set this_item to item i of added_items
            
            if file type of this_item is "JPEG" then
                set my_list to my_list & this_item
            end if
            
        end repeat
        
        open this_folder
        select my_list
        open the selection

    end tell

end adding folder items to

--------------



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org