Perl on Mac finding files by colour?

D

daninbrum

Hi Group,

Thanks ever so much for your starting points on my backup app. I
cobbled together some code (still needs all sorts of cleaning up), and
it works!

Someone notices my app working and decided that they'd love to use
it. This wouldn't be a problem, but they want it with one key
difference... it needs to search by colour.

At the moment, it uses file::find to dig out files with a .doc
extension created since it last ran. However, my colleague wants it to
find files marked with a certain colour (Apple OS-X lets you colour
mark files). Is that possible?

Thanks,

Dan
 
J

Josef Moellers

Hi Group,

Thanks ever so much for your starting points on my backup app. I
cobbled together some code (still needs all sorts of cleaning up), and
it works!

Someone notices my app working and decided that they'd love to use
it. This wouldn't be a problem, but they want it with one key
difference... it needs to search by colour.

At the moment, it uses file::find to dig out files with a .doc
extension created since it last ran. However, my colleague wants it to
find files marked with a certain colour (Apple OS-X lets you colour
mark files). Is that possible?

I don't know much about OS-X, but I'd say if you have access to the
colour mapping, then there'd be no problem: read the mapping and aply it
to each file found and compare the colour thus generated with the colour
the user specified.
 
D

Dan

I don't know much about OS-X, but I'd say if you have access to the
colour mapping, then there'd be no problem: read the mapping and aply it
to each file found and compare the colour thus generated with the colour
the user specified.

I know, but I can't for the life of me work out where this mapping info
is stored.

Thanks,

Dan
 
S

Sherm Pendley

At the moment, it uses file::find to dig out files with a .doc
extension created since it last ran. However, my colleague wants it to
find files marked with a certain colour (Apple OS-X lets you colour
mark files). Is that possible?

It's easy with Mac::Files, which is bundled with Mac::Carbon.

Example:

#!/usr/bin/perl

use strict;
use warnings;

use File::Find;
use Mac::Files;

my @colors = qw(*none* gray green purple blue yellow red orange );

my $searchDir = '/Users/sherm/test_dir';
find (\&wanted, $searchDir);

sub wanted {
my $fname = $File::Find::name;

# Get the file info
my $finfo = FSpGetFInfo($fname);
if (ref($finfo) eq 'FInfo') {
# Get the finder flags, and mask the color bits
my $finder_flags = $finfo->fdFlags;
my $color = ($finder_flags & kColor) >> 1;
print $fname, " = ", $colors[$color], "\n";
}
}

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top