Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 23 votes, 5.00 average. Display Modes
Old 10-22-2002, 01:12 AM   #1
hombre
Triple-A Player
 
Join Date: Jul 2002
Location: Chicago
Posts: 81
Set comments from the command line?

Does anyone know how to set the Finder Get Info comments field from the command line? I thought perhaps SetFile would be able to, but the man page mentions nothing of the sort.

Thanks.
hombre is offline   Reply With Quote
Old 10-22-2002, 12:27 PM   #2
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
Err, would you believe "yes, but with a sledgehammer". Rather than narrate the whole adventure leading to the script below let me just note that the only place I could find a hook into the comment section in the info window was via the Finder's applescript dictionary. From there it was just the standard cut/paste/shout/compile/cry/edit/scream/ routine until things started to behave. One of these days this stuff is going to produce something *useful*: until then you get your script to add in comments from the command line!

The File::Spec::Unix appearance is so that you can use relative filenames on the command line. POSIX file doesn't seem to like these beasties, converting them into absolute old-style mac-paths and thus raising errors about non-existent files.

So save the script between the dashes below as "comment" (for example) in your ~/bin directory. Then "chmod u+x comment", and finally "rehash". Post then you should be able to sidle up to any file that's visible to the Finder and slip a comment between its thighs without anyone noticing. Say you're in your home directory and have a file called "JohnnyDepp" in there: then use something like:

% comment JohnnyDepp CLI BABY

and check out the success or otherwise of the operation with command-I. Works for me. Oh yeah: if you get any errors with the script make sure that the lines containing only "USAGE" and "DNE" do not have any trailing spaces on them.

Cheers,
Paul (ready for someone to jump in with "why don't you just use this really
simple command made for the job...", but not really expecting it to happen)

------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use File::Spec::Unix;
my $file=shift;
my $absfile=File::Spec::Unix->rel2abs($file);
@ARGV or die <<USAGE;

Usage:
======
$0 filename comments

USAGE
my $comment=join ' ',@ARGV;
-e $absfile or die "No such file: $absfile";
my $applescript=<<DNE;
set mypath to "$absfile"
set macpath to (POSIX file mypath) as string
tell application "Finder" to set the comment of file macpath to "$comment"
DNE
`/usr/bin/osascript -sh <<'END'\n$applescript\nEND`;
------------------------------------------------------------------------
pmccann is offline   Reply With Quote
Old 10-22-2002, 02:35 PM   #3
hombre
Triple-A Player
 
Join Date: Jul 2002
Location: Chicago
Posts: 81
Wow... thanks, Paul.

I just spent the weekend acquainting myself with bash. I guess perl is on the schedule for next weekend :/
hombre is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.