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

[MacPerl] Re: making a file/folder invisible



(A copy of this message has also been posted to the following newsgroups:
alt.comp.lang.applescript)

Here is a little library of subroutines to do it in MacPerl.  Perhaps this
is something that can be pulled into another module or something.

I made this long so it can be easily changed to fit specific purposes.

#!perl -wl
use Mac::Files;
use strict;
use constant fInvisible => 16384;

change_file(
    FindFolder(kOnSystemDisk, kDesktopFolderType) . ':test1'
);

change_dir(
    FindFolder(kOnSystemDisk, kDesktopFolderType) . ':test2:'
);


sub change_file {  # switch file between visible / invisible
    my($file, $flags, $info) = @_;
    $flags = get_fflags($file);

    set_fflags($file, is_visible($flags) ?
        make_invisible($flags) : make_visible($flags));
}

sub change_dir {  # switch dir between visible / invisible
    my($dir, $flags, $info) = @_;
    $flags = get_dflags($dir);

    set_dflags($dir, is_visible($flags) ?
        make_invisible($flags) : make_visible($flags));
}

sub get_fflags {  # get file flags
    my $info = FSpGetFInfo($_[0]) or die "Can't get flags for $_[0]: $^E";
    $info->fdFlags;
}

sub get_dflags {  # get dir flags
    my $info = FSpGetCatInfo($_[0]) or die "Can't get flags for $_[0]: $^E";
    $info->ioDrUsrWds->frFlags;
}

sub set_fflags {  # set file flags
    my($file, $flags, $info) = @_;
    $info = FSpGetFInfo($file) or die "Can't get flags for $file: $^E";
    $info->fdFlags($flags);
    FSpSetFInfo($file, $info) or die "Can't set flags for $file: $^E";
}

sub set_dflags {  # set dir flags
    my($dir, $flags, $info, $d_info) = @_;
    $info = FSpGetCatInfo($dir) or die "Can't get flags for $dir: $^E";
    $d_info = $info->ioDrUsrWds;
    $d_info->frFlags($flags);
    $info->ioDrUsrWds($d_info);
    FSpSetCatInfo($dir, $info) or die "Can't set flags for $dir: $^E";
}

# is item invisible?
sub is_visible {return ((shift() & fInvisible) ? 0 : 1)}

sub make_visible {  # make flags visible
  my $flags = shift;
  return (($flags & fInvisible) ? $flags ^ fInvisible : 0)
}

sub make_invisible {  # make flags invisible
  my $flags = shift;
  return (($flags & fInvisible) ? 0 : $flags | fInvisible)
}

__END__

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch