Installing ImageMagick - how to guide

2008-04-15 Thread Peter N Lewis
I've fought ImageMagick install a few times, and again recently (it 
is better, but still a pain).


One issue that affected me and probably would not affect others is I 
needed to keep the non-universal builds of libjpeg et al out of 
/usr/local, hence the prefix used in this, but probably not needed 
for most users.


Note the lines with [] include instructions - you can't just run this 
lot as a script.


Hopefully this is useful to someone,
   Peter.

cd
mkdir install
cd install
setenv MACOSX_DEPLOYMENT_TARGET 10.4
setenv LDFLAGS -L$HOME/unix/local/lib


[Install libtiff]

curl -O ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.8.2.tar.gz
tar zxf tiff-3.8.0.tar.gz
cd tiff-3.8.2
./configure --enable-shared --prefix=$HOME/unix/local
make
make test
make install
cd ..

[Install libpng]

curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.25.tar.gz
tar zxf libpng-1.2.25.tar.gz
cd libpng-1.2.25
./configure --enable-shared --prefix=$HOME/unix/local
make
make install
make test
cd ..

[Install libjpeg]

curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar zxf jpegsrc.v6b.tar.gz
cd jpeg-6b/
[For intel, edit configure and add 'i386' to the end of the ltconfig line]
./configure --enable-shared --prefix=$HOME/unix/local
ln -s `which glibtool` ./libtool
make
make test
make install
cd ..

[Install freetype]

curl -O 
hthttp://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz

tar zxf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --enable-shared --prefix=$HOME/unix/local
make
make install
cd ..

[install ghostscript]

curl -O 
http://superb-west.dl.sourceforge.net/sourceforge/ghostscript/ghostscript-8.62.tar.gz

tar zxf ghostscript-8.62.tar.gz
cd ghostscript-8.62
./configure --enable-shared --prefix=$HOME/unix/local
make
[Comment out #include cups/cups.mak in Makefile]
make install
cd ..

[Install imagemagick]

curl -O  ftp://mirror.aarnet.edu.au/pub/ImageMagick/ImageMagick-6.2.5-5.tar.gz
tar zxf ImageMagick-6.2.6-1.tar.gz
cd ImageMagick-6.2.6
./configure --prefix=$HOME/unix/local
make
sudi make install
cd ..

--
  Keyboard Maestro 3.0 Now Available!

Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
http://www.stairways.com/   http://download.stairways.com/


Re: CamelBones Leopard PPC?

2008-02-10 Thread Peter N Lewis

My CamelPhones photo program stopped working and now just prints:

Error creating CFBundle from support bundle at URL 
file://localhost/Library/Frameworks/CamelBones.framework/Libraries/darwin-thread-multi-2level-5.8.8.bundle


I tried checking out the CVS but ./configure; make just spews errors 
starting with StubInit.m:17: warning: ISO C90 forbids mixed 
declarations and code and continuing on.


Is there a simple way of getting this working?

Thanks,
   Peter.

--
Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
http://www.stairways.com/   http://download.stairways.com/


Re: Proposed Mac::Pasteboard

2008-01-29 Thread Peter N Lewis

  and then write Mac::Clipboard using Mac::Pasteboard to expose only the

 clipboard.  In the SEE ALSO section you can reference Mac::Pasteboard
 and people who need the advanced functionality can find it.


Interesting thought. The straightforward implementation would be to
have Mac::Clipboard depend on Mac::Pasteboard (since there's no
simplified clipboard interface that I have found). But it seems un-
parsimonious to me to use namespace for maybe a dozen lines of Perl,
since right now the clipboard part is on the order of


Given that Pasteboard offers a lot more functionality than just 
pbcopy/pbpaste, I would have though Clipboard would similarly offer 
all the functionality of Pasteboard, except only to the default 
standard clipboard.


So where Mac::Pasteboard might have a function that returns the list 
of flavors of the fifth item in the a specific pasteboard, 
Mac::Clipboard would have a function that returns the list of flavors 
of the fifth item, but only in the default system clipboard.


Obviously, you want some nice easy routines to extract the clipboard 
flavours as text (getting the unicode text if possible, the plain 
text if not), but you want that same functionality for all 
Pasteboards as well as for the system clipboard, so you would again 
have a function in Mac::Pasteboard that returns the text of the top 
item of a specified pasteboard and a function in Mac::Clipboard that 
returns the text of the top item in the system clipboard.


If Mac::Pasteboard is implemented in a functional manner, then you 
could use undef as the pasteboard parameter to specify the system 
pasteboard.


If Mac::Pasteboard is implemented in an OO manner, then 
Mac::Clipboard would be essentially identical, except instead of a 
factory function that takes a pasteboard name, it has just a factory 
function that returns the Mac::Pasteboard object for the system 
clipboard.


But regardless of the details, I think Mac::Clipboard would want to 
be far more than just an interface equivalent of pbcopy/pbpaste.


Enjoy
   Peter.

--
Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
http://www.stairways.com/   http://download.stairways.com/


Re: Mac OS alias from Perl

2007-12-09 Thread Peter N Lewis

At 19:01 -0500 8/12/07, Dan Neville wrote:
Does anyone know how to make a Mac OS alias in Perl?  So, I wish to 
have Perl create aliases in multiple directories rather than copy 
the original file.


There actually is no API call to create an alias file.

You can do it in Perl as described at

http://use.perl.org/~pudge/journal/10437

Alternatively, you can make a new alias via AppleScripting the Finder as:

set thaAlias to Harddisk:Users:peter:thefile.cpp as alias

tell application Finder
set f to make new alias file at desktop to thaAlias
end tell
f

Which will return the alias file created.

Enjoy,
   Peter.

--
Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
http://www.stairways.com/   http://download.stairways.com/


Re: Detecting OS X version from perl

2007-11-18 Thread Peter N Lewis

At 17:52 -0700 15/10/07, Chris Nandor wrote:

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (David Cantrell) wrote:
  ie whether it's 10.0, 10.1 etc, I don't care about the difference

 between 10.3.3 and 10.3.4.


This is nice in that it doesn't depend on external processes (sw_vers,
Finder) or files.

   use Mac::Gestalt qw(%Gestalt gestaltSystemVersion);
   (my $version = sprintf(%x, $Gestalt{gestaltSystemVersion()})) =~
  s/^(\d+)(\d)(\d)$/$1.$2.$3/;


Note that gestaltSystemVersion tops out at .9, so it will return 
10.4.9 for all future 10.4 updates (including 10.4.10 and 10.4.11 
etc).


Fortunately, this does not affect you.

You can use gestaltSystemVersionMajor, gestaltSystemVersionMinor, and 
gestaltSystemVersionBugFix to return the three parts of the version 
(10, 4 and 11).


Enjoy,
   Peter.

--
Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
http://www.stairways.com/   http://download.stairways.com/


Re: iCal modules

2006-08-10 Thread Peter N Lewis

At 20:55 -0500 10/8/06, Ken Williams wrote:

 locate gluemac


While on this topic, one of the first things I do to any newly 
installed Mac that I will use is to move the locate database update 
from weekly to daily and remove the run as nobody so it runs as 
root (otherwise it does not see any of my own files!).


Add /etc/daily.local:

#!/bin/sh -
#
#   @(#)daily   8.2 (Berkeley) 1/25/94
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin

if [ -x /usr/libexec/locate.updatedb ]; then
echo 
echo Rebuilding locate database:
locdb=/var/db/locate.database
touch ${locdb}; chown nobody ${locdb}; chmod 644 ${locdb}
# echo /usr/libexec/locate.updatedb | nice -5 su -fm nobody 21 
| sed -e '/Permission denied/d'

/usr/libexec/locate.updatedb
chmod 444 ${locdb}
fi

Delete the locate.updatedb code from /etc/weekly (unfortunately, you 
have to do this to avoid it clobbering the good database with the bad 
database for up to one day a week).


After this, locate works like Spotlight should, ie finds everything, 
finds it very fast.


Eg, locate s3 | grep pdf - find the Amazon S3 documentation (| 
xargs bbedit for good measure ;-)


Enjoy,
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Re: Mac / Perl / 3D

2006-07-29 Thread Peter N Lewis

Thanks for the various answers.

I have done the Perl - POV-RAY source before, as well as Perl - 
3DML text format before.


I guess I could also use any scriptable drawing package (see 
http://www.peter.com.au/programming/scripted-drawing.html ;-) and 
do my own 3D conversion as necessary.


None of this seems entirely satisfactory though...

Thanks for the ideas.
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Re: How to get a pid

2006-07-29 Thread Peter N Lewis

I could not figure out how to get the tool process's id. But by observing,
I notice that its pid is 'always' equals to child process's pid+1.


PIDs can wrap, so there is no guarantee of this at all.

Why do you call waitpid with -1, when you know the pid you want to 
wait on ($kidpid).


The reason for zombies (ie, (perl)) is normally that the process 
has died, but no one has requested the termination status (with 
waidpid or its cousins).


I admit to having no idea what execEggplant does.  But it sounds like 
it is running another subprocess.  Really, it needs to wait on that 
sub process and return when it is complete.


You could use killall to find the process by name:

killall -s -d Preview

although that is always a bit risky if the process name is not known 
and unique.


Otherwise you have problems.
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Mac / Perl / 3D

2006-07-25 Thread Peter N Lewis
I'm interested in producing some drawings/diagrams/pictures based on 
3D data/objects generated from Perl.  Something that would allow me 
to write code that generates boxes, cylinders, spheres, etc with 
various colours and material styles and generate an image (or 
potentially an animation).


Any suggestions?  The best bet seems to be to use SDL_Perl, although 
a brief look seems to indicate I'll be installing packages for the 
next month.


Thanks for any hints or warnings,
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Re: Regex and Mac vs UNIX line endings

2006-07-21 Thread Peter N Lewis

At 19:25 +0200 20/7/06, kurtz le pirate wrote:

hum... is 'end of line' caracter important ?

if not, you can do something like that :
while (FILE) {
  chomp;
  if (/?/) { ... }
  }

yes ? no ?


Not really, because if the file is Mac line endings, then that will 
read the entire file in a single gulp.  Also, if the file is DOS line 
endings, then the chomp will remove only the linefeed (unless you 
have changed $/ to CRLF, in which case it will not remove a single 
linefeed).


If you fist check the fie and determine the line endings (and the 
file has consistent line endings, which is not always the case) and 
set $/ appropriately, then what you suggest will work.


Enjoy,
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Re: Regex and Mac vs UNIX line endings

2006-07-20 Thread Peter N Lewis

I'm processing a string with embedded newlines. For testing I was
storing the text in __DATA__ and slurping it into a string. This works
fine. However when I read in a file, I'm having trouble with the line
endings. Matching begining/end of logical lines is not working as I
expect. Regexes like the one below match when using the DATA filehandle,
but don't when opening other text files on my Mac.

$text =~ s/^Text to match.*$//m;

Is this due to UNIX '\n' vs. Mac '\r' line endings? I assumed the 'm'
modifier would recognize any line ending.

Oh what to do?


You have several possibilities, depending on what you are trying to do.

You could explicitly use either line ending, as it:

$text =~ s/(\012|\015|\A)Text to match[^\012\015]*(\012|\015|\z)/$1$2/;

or using backward/forward assertions:

$text =~ s/(?:\A|(?=\012|\015))Text to match[^\012\015]*(?=\012|\015|\z)//;

(the convoluted backward assertion is required because backward 
assertions must be fixed lengths)


Or you could convert $text to \n line endings:

$text =~ s/(\015\012|\012|\015)/\n/g;
$text =~ s/^Text to match.*$//m;

Or you could detect the line ending and explicitly use it.

Enjoy,
   Peter.

--
Check out Interarchy 8.1.1, just released, now with Amazon S3 support.
http://www.stairways.com/  http://download.stairways.com/


Re: Formatting uploaded images

2006-02-15 Thread Peter N Lewis

At 14:52 + 15/2/06, Moisés Chicharro wrote:

My main aims being:

- check uploaded image filesize is not too large (most important)


Others have explained how to do this.


- check uploaded image physical pixel size


This can be done relatively easily by parsing the JFIF tags.

The JPEG/JFIF file format is just:

FF D8 - Start of Image marker
Followed by a sequence of headers:
  FF xx - header tag xx
  length (two bytes, big endian) - length of header including these two bytes
  header data

The actual data for the image follows the Start 
of Scan marker (FF DA) header, and the header you 
want is the Start of frame marker (FF C0) header, 
where the data for the header is:


P -- one byte: sample precision in bits (usually 8, for baseline JPEG)
Y -- two bytes
X -- two bytes

other stuff see 
http://www.obrador.com/essentialjpeg/headerinfo.htm 
for details.


Parsing this format sufficiently to read the X  
Y size should not be very challenging.



- change uploaded image physical pixel size (if possible without module)


As mentioned, you could just specify height and 
width in your HTML/CSS to set a maximum display 
size.  Actually reprocessing the image to change 
the size without a library would be quite 
challenging.


Enjoy,
   Peter.

--
http://www.stairways.com/  http://download.stairways.com/


Re: Detecting file's line endings

2005-12-22 Thread Peter N Lewis

At 15:15 + 22/12/05, James Harvard wrote:
I'm trying to detect a file's line endings (\r\n for DOS, \r for Mac 
and \n for Unix as I'm sure y'all know).


Is there any easy way to do this?


use Fcntl;

sub get_line_ending_for_file {
  my( $file ) = @_;

  my $fh;
  sysopen( $fh, $file, O_RDONLY );
  sysread( $fh, $_, 33000 );
  close( $fh );

  return /(\015\012|\015|\012)/ ? $1 : \n;
}

Adjust the 33000 number to whatever maximum line size you think might 
be appropriate.


Enjoy,
   Peter.



I don't want to slurp the whole file, because it could be 14 MB or 
more, so I wanted to read in chunks until I got to a line break. 
However I can see a potential problem ending a chunk half way 
through a DOS \r\n, so then you just get \r which makes it look like 
a Mac formatted file.


Anyway, I started to roll my own code for it, and because I'm new to 
Perl I hoped that one of you kind souls would have a quick look 
(below) to check that I've got the right idea of how to do this sort 
of thing with Perl. (It seems to work with my tests, but that 
doesn't necessarily mean that it is a robust method!)


Also, I assume that one can pass a file handle to a sub-routine?
$/ = sniff_line_endings(INFILE) ;

Many thanks,
James Harvard

open (INFILE,$filename) or die Couldn't open ;
$/ = \50 ;
my $taste = '' ;
my $lb = undef ;
until ($lb) {
$taste .= INFILE ;
if ($taste =~ /\r\n/) {
$lb = \r\n ;
# DOS line endings
} elsif ($taste =~ /\r(?!$)/) {
$lb = \r ;
# Mac line endings
} elsif ($taste =~ /\n/) {
$lb = \n ;
# Unix line endings
}
}
$/ = $lb ;
seek INFILE, 0, 0 ; # reset the file read pointer
# do while(INFILE) stuff



--
http://www.stairways.com/  http://download.stairways.com/


Re: How to find out if an application is running

2005-10-14 Thread Peter N Lewis

At 20:02 -0700 13/10/05, Ted Zeng wrote:

Here is the fun part: I made a killapp.pl script and
Call it to kill Bridge with
`killapp.pl Bridge `

And it kills itself.

As it turned out, the script finds itself from the list because the
Command line includes Bridge(or Adobe Illustrator for Illustrator).


The standard trick for this, if the search is a regular expression, 
is to surround one of the letters with [], ie:


killapp.pl '[B]ridge'


It works. But somebody probably laughs at it.


It's hardly the first time, indeed the general find this application of

ps auxw | grep 

inevitably finds the search command unless you use a trick like the above, or:

ps auxw | grep  | grep -v grep

Enjoy,
   Peter.

--
http://www.stairways.com/  http://download.stairways.com/


Re: CamelBones on Intel? Maybe not.

2005-06-08 Thread Peter N Lewis

My main question about the change to Intel is why the developer pack,
whatever it was, costs so much? What do you get for your $999? I was
expecting something free to download to developer members.


As others have said, they throw in a computer.


Keep in mind the Developer Transition System hardware is only on loan 
and needs to be returned (by the end of 2006 I think) and has other 
restrictions (basically, I think Apple is treating it like the normal 
Seed hardware which is loaned, not sold, and has lots of 
restrictions, like fixed location, etc).


Not that I can find any actual details on this currently, but if you read:

http://developer.apple.com/transitionkit.html

You will note it says Use of a Developer Transition System, not 
actual ownership of.


Personally, I prefer the Be hardware seeding (they gave me a free 
box, and then another one later when they upgraded them), but then it 
didn't work out that well for Be in the end unfortunately...

   Peter.
--
http://www.stairways.com/  http://download.stairways.com/


Re: BBEdit/Interarchy

2005-06-03 Thread Peter N Lewis

At 7:39 +0900 4/6/05, Joel Rees wrote:

On 2005.6.4, at 04:31 AM, Ken Williams wrote:
Actually, it *would* entirely solve the problem.  Renaming a file 
is an atomic operation, there's no point at which anybody could 
get a partial file.  People still reading the old file would be 
fine too, even if the rename happened while they're in the middle 
of reading; the old file is readable until they close it.


Peter pointed out in a private email that this isn't reliable using 
FTP's rename functionality


I'd like a peek at what he wrote, if nobody minds.


Sorry, I was trying to reduce the noise as we drift further and 
further off topic, but it seems ti just added more.


At 23:27 +0800 3/6/05, Peter N Lewis wrote:
We're getting a bit too esoteric to continue on the list, but this 
depends on the FTP server allowing rename/overwrite, which is far 
from guaranteed, even under unix.  There are quite a few FTP servers 
which will give an error in that case, so you would need to delete 
the file first and then rename, destroying the atomicness of the 
operation.


 (if your FTP even supports it) - what I meant in the above, though 
I wasn't clear, was to use /bin/mv on the server, not a rename 
through the FTP connection.


Now, I wouldn't want to stir too much oil into the water, but I'm 
imagining strange things like, ssh would not have such problems 
(assuming you knew that the server was a regular *NIX server and the 
server's file system was a system with proper inodes)?


Yes, presuming you ssh in, and then apply the old permissions to the 
new file and then do a mv (much like the script Bill ended up 
writing), you'd be safe for at least the mainstream unix systems I 
would think.


Enjoy,
   Peter.

--
http://www.stairways.com/  http://download.stairways.com/


Re: What Perl editor do you recommend?

2005-03-02 Thread Peter N Lewis
Some friends have recommended vim and emacs to me. And one of the 
reasons is he can remotely edit a text file very easily.
This has been mentioned a few times, but of course 
TextWrangler/BBEdit both support Edit via FTP/SFTP, so presuming you 
are SSHing to your target machine, then you can easily edit remote 
files with TextWrangler/BBEdit.

For example, on the target machine while logged in via ssh, you can do this:
ssh [EMAIL PROTECTED] bbedit sftp://[EMAIL PROTECTED]/perl/Peter/Tools.pm
I'll leave as an exercise to the perl hacker as to how to have to set 
up[ an alias and script to do this by typing

rbbedit Tools.pm
Enjoy,
   Peter.
--
http://www.stairways.com/  http://download.stairways.com/


Re: Taint mode (was Re: Variables in external file)

2005-02-20 Thread Peter N Lewis
Which reminds me... I've been using the #!/usr/bin/env
perl shebang for easier distribution, but env doesn't
like switches. Is there a way to set taint mode via
`use` or the like (ala use warnings; for -w). I can't
seem to locate anything in the manuals other than the
-T flag.
Correct me if I'm wrong, but the primary reason for using
#!/usr/bin/env perl
is to avoid hardcoding the path to perl.  The #! requires an absolute 
path, and so if you use #!/usr/bin/perl, you wont work if the 
customer is using /usr/local/bin/perl.

On the other hand, Taint mode's purpose is to ensure that your 
program cannot do anything nefarious due to user input.

In this case, the user's PATH environment variable would control 
which perl you executed, thus rendering all actions suspect. 
Generally the first thing a Taint mode program would do is clear the 
PATH environment variable to '/bin:/sbin' or the like.

Thus any attempt to use both /usr/bin/env perl and taint mode is 
fraught with danger.

Regardless, the only place you can use the -T switch is on the 
command line unless the script is executed directly in which case the 
#! line must be an absolute path to perl.

I have some vague memories of some sort of hack to do something along 
the lines of:

#!/bin/sh
perl -T $0 (or whatever the variable is for this script path).
with some magic to hide the perl command from the perl interpreter. 
But my memory is insufficient to the task and this would still leave 
you susceptible to the user's PATH which you may want to support but 
which is quite dangerous to combine with Taint mode.

Enjoy,
   Peter.
--
I was away from Feb 12 - Feb 19, sorry for any email delays.
http://www.stairways.com/  http://download.stairways.com/


Re: Setting the name of screenshots (etc)

2004-10-25 Thread Peter N Lewis
At 23:16 -0700 24/10/04, Rich Morin wrote:
I find it a nuisance to have to hunt down the Picture #.pdf file
to rename it.  It seems as if there should be a more direct way to
do this.  For instance, I'd be happy to have a Open Dialog come up.
Am I missing something obvious here?  I found a cute hack in Mac
OS X Unleashed, 2e: build a wrapper script around the command
(/usr/sbin/screencapture).  Unfortunately, this still begs the
question of how to bring up a file dialog box, etc.  Help?
-r
P.S.  A Perlish solution would be Just Fine, but any reasonable
  ideas and comments are acceptable...
My annoyance was not with the lack of naming, but with the fact that 
screen shots come out at 300 dpi rather than being pixel accurate.

Eventually I gave up and did exactly as described, wrapped 
screencapture and used our Keyboard Maestro to map the command-shift 
keys to perl scripts instead.

The perl scripts each look something like this:

#!/usr/bin/perl -wT
use lib /Users/peter/perl
use warnings;
use strict;
#use diagnostics;
$ENV{PATH} = /bin:/usr/bin;
use Peter::ScreenCapture;
Peter::ScreenCapture::screen_capture_selection_to_file();

And the ScreenCapture.pm follows.  A tricky part is detecting a 
canceled capture (eg pressing the escape key)  because screencapture 
does not give any indication.  It uses GraphicConverter to save the 
file.  Currently, it mimics the systems Picture #.tiff, but if you 
change the AppleScript code for that to:

tell application GraphicConverter
activate
try
save as window 1
end try
end tell
then GC will prompt for a filename.
Enjoy,
   Peter.

package Peter::ScreenCapture;
use 5.006;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our $VERSION = '1.00';
our @EXPORT_OK = qw(
screen_capture_screen_to_file
screen_capture_screen_to_clipboard
screen_capture_selection_to_file
screen_capture_selection_to_clipboard
screen_capture_clipboard_to_file
);
our @EXPORT = qw(
);
our %EXPORT_TAGS = ( 'all' = [ @EXPORT_OK ] );
our $screencapture = '/usr/sbin/screencapture';
sub screen_capture_screen_to_file {
if ( screen_capture_screen_to_clipboard() ) {
screen_capture_clipboard_to_file();
}
}
sub screen_capture_screen_to_clipboard {
pbset( 'Screen Capture' );
my $result = system( $screencapture, '-c' );
return pbget() ne 'Screen Capture';
}
sub screen_capture_selection_to_file {
if ( screen_capture_selection_to_clipboard() ) {
screen_capture_clipboard_to_file();
}
}
sub screen_capture_selection_to_clipboard {
pbset( 'Screen Capture' );
my $result = system( $screencapture, '-ci' );
return pbget() ne 'Screen Capture';
}
sub pbset {
my ( $what ) = @_;
open( OUT, |/usr/bin/pbcopy ) or die;
print OUT $what;
close( OUT );
}
sub pbget {
open( OUT, /usr/bin/pbpaste| ) or die;
local undef $/;
my $what = OUT;
close( OUT );
return $what;
}
sub screen_capture_clipboard_to_file {
require Mac::OSA::Simple;
my $n = 1;
$ENV{HOME} =~ m!^(/\w+/\w+)$! or die Bad Home Directory $ENV{HOME};
my $path = $1/Desktop/Picture.tiff;
while ( -e $path ) {
$path =~ s!( ?\d*\.tiff)! $n.tiff! or die;
$n++;
}
  if ( open( my $fh, , $path ) ) {
close( $fh );
  }
 Mac::OSA::Simple::applescript( EOM );
tell application GraphicConverter
new image from clipboard
save window 1 in alias (posix file $path) as TIFF
close window 1
end tell
EOM
}
1;

--
http://www.stairways.com/  http://download.stairways.com/


Re: ImageMagick/PerlMagick on Panther

2004-09-23 Thread Peter N Lewis
And finally, I guess, this is basically all I want to use the ImageMagick for:
Image resizing.
Image compression - jpg
Finding image DPI
Finding image size
Clean up image (sharpen, etc.)
Well, other than sharpen, you can actually do all that in Image 
Events which comes with Mac OS X (10.3?).

tell application Image Events
set img to open file Zany:Users:peter:Example.jpg
set x to {resolution of img, bit depth of img, dimensions of img}
scale img by factor 0.5
crop img to dimensions {500, 500}
save img as JPEG in Zany:Users:peter:ExampleOut.jpg
x
end tell
returns {{180.0, 180.0}, millions of colors, {2272.0, 1704.0}}
Accessing Image Events via AppleScript or AppleEvents can be done 
from Perl using many different techniques using a lot smaller hammer 
than ImageMagick.

Not that I would want to dissuade anyone from using ImageMagick, it 
is very useful, I use it a lot, and I'm one of those who posted the 
weary howtos on getting the darned thing working in Mac OS X's 
perl, so I certainly wouldn't want to have anyone else miss out on 
the fun.  And Image Events is pretty sucky.  But it might be enough 
to get you started, as long as you keep the image access areas of 
your code constrained you should be able to change it later and plug 
in something more powerful.

Another alternative which I've used successfully is to script 
GraphicConverter or Photoshop.

Enjoy,
   Peter.
--
http://www.stairways.com/  http://download.stairways.com/


Re: BBEdit 8.0

2004-09-10 Thread Peter N Lewis
At 14:50 +1000 10/9/04, John Horner wrote:
Multi-file regular expression find  replace functionality, with 
nameable saveable expressions
That's the killer-app feature for me. I could actually say that I 
think it's BBEdit that gave me my first glimpse of the power of Perl.
Also, if you're a Perl  BBEdit user and haven't already, check out 
the BBEdit  Help - Grep reference, it is a very useful reference for 
all the PCRE stuff, especially useful for things in the Advanced Grep 
Topics section like zero width  negative lookbehind assertions (which 
if you're like me you can never remember what sequence of line noise 
they might correspond to).

BBEdit is a very powerful text editor, but where it really out shines 
other text editors is its attention to detail (like handling a file 
being renamed underneath it and updating as the file changes, and 
such) and the way it handles multiple files (I like the Window 
palette, but now also with multiple documents per window), especially 
for things like multifile find  replace

Enjoy,
   Peter.
--
http://www.stairways.com/  http://download.stairways.com/


Re: Simple perl script send email

2004-05-03 Thread Peter N Lewis
\Mail is an incredibly complex thing, combine that with trying to 
handle IPC issues when shelling out, then you are reinventing a 
wheel that should definitely not be re-invented.   Net::SMTP is an 
example, though probably a more difficult one, there are lots,

http://search.cpan.org/modlist/Mail_and_Usenet_News/Mail
Mail::Mailer
Mail::Sender
MIME::Lite
Are some good choices, I use Mail::Box but generally it is way 
overkill, but since I know I will have it installed I usually 
default to it.
I wanted to switch from using sendmail in a pipe to using 
Mail::Sender, but I found that Mail::Sender seems to take a lot 
longer to send a message - not so much an issue for sending out 
status messages, but a serious problem for sending out newsletters or 
the like.
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: Updating icons in OS X

2004-01-28 Thread Peter N Lewis
Currently I'm using AppleScript to work on files and then
send them out to different folders on different servers.
But I'm running into problems where users don't know that
their file is finished because the icon doesn't appear in
their folder.
Generally they should appear if you touch the folder (ie, change 
the modification date of the folder to now (or one approach I've 
heard of is to change the modification date of the folder by one 
second)).

There is also an API call, FNNotify, which will do this, but only on 
the local machine.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: confusing bulltes

2004-01-11 Thread Peter N Lewis
At 9:02 PM -0500 11/1/04, Vic Norton wrote:
When I write another script to print out the bytes under __DATA__, I see
A5 if I execute the script from Terminal, and I see E2 80 A2 if 
I run the script fom BBEdit, either directly or Run in Terminal. 
But BBEdit can see A5. It just can't see it as DATA. If I write 
a script to look for A5 in the file that contains the single 
option-8 data element and run the script from BBEdit, BBEdit has no 
trouble spotting the A5 at the end of the file.
When you 'run the script from BBEdit, either directly or Run in 
Terminal.', what actually happens is BBEdit saves the file in a 
temporary file and then executes it.

It would seem that BBEdit is saving the temporary file in UTF8 format 
rather than the specified format.

Actually, check your BBEdit preferences for Text Files: Opening, and 
also Saving.  There is a configuration in there for Default Text 
Encoding and Guessing Text Encoding.  It seems when BBEdit saves the 
temporary file, these are used instead of the current file's text 
encoding.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: AE Monitor

2003-12-11 Thread Peter N Lewis
At 10:50 PM -0800 10/12/03, Chris Nandor wrote:
Anyone used this?

http://www.apple.com/downloads/macosx/development_tools/aemonitor.html

Downloading now, will be trying out laterish.
It looks pretty cool, please tell us all what you think.

Personally, I just recently used the AEDebug stuff in the Terminal:

setenv AEDebug 1
setenv AEDebugSends 1
setenv AEDebugReceives 1
/Applications/AppleScript/Script\ Editor.app/Contents/MacOS/Script\ Editor
and then you can see all the events going to/from the Script Editor.

But at $5 (why!) if its any good at all it would be worthwhile 
(personally I don't know why he dropped the price to $5, $15 would be 
about right IMHO, presuming it works well, and if it doesn't, it's 
not worth anything...).

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: Can I run one Perl script from another ?

2003-10-02 Thread Peter N Lewis
Having spent hours trying to find a simple answer (learning lots 
along the way), I'm still hoping that there is a simple answer:

Can I run one Perl script from inside another?

I have a large set of scripts that I usually run one-at-a-time, but 
I want to create a controlling script so that I can run one or more 
of these scripts in sequence.
Sure, I do this to run all the various update scripts for my project 
when something major happens (like CVS checkout for example).

#!/usr/bin/perl

use warnings;
use strict;
use lib $ENV{HOME}/perl;
my $perl = '/usr/bin/perl';

system( $perl, $ENV{HOME}/perl/clean-project.pl, 'DO' );
system( $perl, $ENV{HOME}/perl/MakeInterarchyMake.pl );
system( $perl, $ENV{HOME}/perl/MakeInterarchyBridge.pl );
system( $perl, $ENV{HOME}/perl/check-msg.pl, 'REZ' );
system( $perl, $ENV{HOME}/perl/MakeBundleInstall.pl );
system( $perl, $ENV{HOME}/perl/FileListType.pl );
Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: opening files whose names contain CRs?

2003-09-14 Thread Peter N Lewis
At 7:23 PM -0700 13/9/03, Rich Morin wrote:
At 8:14 PM -0600 9/13/03, Doug McNutt wrote:
Icon\r files appear when, in earlier Mac OS's, a folder ...
This is interesting, but it doesn't answer the question of how one
opens a file with this sort of name weirdness.  Basically, I think
I've found a bug.  Prolly should check for it in Panther...
There is no problem with opening a file with a CR in its name.

The problem is only with a file who ends in any sequence of carriage 
returns or line feeds.  It would appear these are stripped from the 
file name by perl (presumably trying to be helpful so you can open a 
file even if the name is read from a file and you forget to chomp it).

It looks like the pattern stripped is [\r\n]*$ which is a shame.  If 
it was \r?\n? then you could fix it by appending \r\n to the file 
name to ensure it was stripped and you were left with your name 
unmangled.

The only thing I can think of is:

try sysopen and see if it has the same hack
or
try Mac::Carbon and see if you can use it to access the file some how 
(or potentially rename the file, access it and rename it back).

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: OT: Mac OS X's built-in URL architecture

2003-07-14 Thread Peter N Lewis
At 10:25 AM +0900 15/7/03, Thilo Planz wrote:
sherlock://com.apple.flights?new_windowtoolbar=hidden

itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?songTerm=Bohemian
I am amazed by these sherlock:// and itms:// URLs.

Does anyone know how this works, if everyone can register 
protocols for their own apps (or if it is closed to Apple's) and 
where I can find some documentation about this architecture?

Are other applications also using this?
Anyone can register to be a helper for any protocol with Internet 
Config.  Of course, a proper URL protocol would need to go through 
the standards process, etc, but that's for standards weenes right?

For example, we register interarchy: protocol handler for Interarchy 
to do various things (many of the menu commands can be got through an 
interarchy: URL).  We also support various others for looking up DNS 
names and such.

As long as you stay away from protocol names that other apps are 
going to use, you can make up your own and make up your own URL 
format, register it with Internet Config and use it as much as you. 
The standards guys will probably cringe/scream of course.  But if you 
use, for example, your app name as the protocol name, you should be 
fairly safe, since the standards guys could not use it without 
getting in to trademark issues.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: head vs. head

2003-07-11 Thread Peter N Lewis
At 9:55 AM -0400 11/7/03, Sherm Pendley wrote:
On Friday, July 11, 2003, at 09:26 AM, Elizabeth Mattijsen wrote:

Surely the install script can be made smart enough to make [n] the 
default on Mac OS X?
Even if the test is done in very general terms - i.e. if it were 
written to look for a case-insensitive filesystem instead of for a 
specific OS - you'd still need such a system to verify the test. In 
practical terms, that means testing it on a Mac - I don't know of 
any other UNIX that uses a case-insensitive filesystem.
Not really wanting to get involved in this debate over again, but 
really a program should not replace an xisting file with a link by 
default, so perhaps the test should be if there already exists an 
HEAD which is not a link (or if they are hardlinks, a HEAD that is 
not a link to lwp_doit or whatever the real command is, or a weak 
test, not the same size as lwp_doit which would be close enough), 
then default to [n].  On the Mac system, HEAD and head are the same 
so the test would work for this case, and could easily be tested on 
any other unix system.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://documentation.interarchy.com/


Re: copy files with everything?

2003-03-31 Thread Peter N Lewis
At 9:16 +0200 31/3/03, Wischnewski, Berndt wrote:

copies just the file, but the resulting test2.doc has lost the icon, 
file type and creator. I think there must be a way, which I simply 
dont now.
/Developer/Tools/CpMac

usage: CpMac [-r] [-p] [-mac] source-path dest-path
   CpMac [-r] [-p] [-mac] source-path... dest-dir
Enjoy,
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: magic bullet needed for Perl upgrades on Mac OS X

2003-03-03 Thread Peter N Lewis
At 2:37 PM +1100 2/3/03, Charlie Garrison wrote:
On 28/2/03 at 12:39 PM, Peter N Lewis [EMAIL PROTECTED] wrote:

In that case, don't even think about trying to build a smaller bundle
- people in general will not even blink before 10MB these days, and
in general wont worry about it until it is *much* bigger than that.
I disagree. For me, I don't blink if it's under 2MB. But anythinbg over that I
make a conscious decision about whether I really want it. I find file size to
be a very important factor in deciding whether to download. Not everyone has
even 56K connections (much less broadband) if they don't live in/near a city.
I was not talking about all people, just people in general.  I tend 
to be reasonable size sensitive myself.  But from endless examples I 
can say pretty definitively that the vast majority of people are very 
bandwidth insensitive.  give them a choice of smaller or better and 
they will pick better almost every time, even with massive file sizes.
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: no-no?

2003-03-02 Thread Peter N Lewis
At 11:38 AM -0600 1/3/03, Ken Williams wrote:
Actually, since I've done this, installing 5.8 over your stock perl 
does not seem to cause any problems in general.
Maahahahahah, NOT YET, it hasn't!
Grin.

Actually, I tend to do these kinds of bad idea perl installations 
from time to time, just because I know I can deal with it if things 
get hosed, and I like the experimentation.  But I wouldn't recommend 
it to someone that just wants perl as a working tool in good shape. 
Sounds like you're probably of the same opinion, you don't mind 
tinkering a little with things if/when they break.
Absolutely.  I wouldn't recommend it to everyone, I'm just reporting 
that if you're game, it so far hasn't proved to be a disaster ;-)

Besides, who wanted Quicktime 6.0.2 anyway, and I bet they fixed the 
script for 6.0.3!

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: magic bullet needed for Perl upgrades on Mac OS X

2003-02-27 Thread Peter N Lewis
At 9:39 PM -0500 27/2/03, Sherm Pendley wrote:
It seems like it would bulk up the download, though. For many folks, 
disk space is plentiful - but bandwidth is not.
You can actually probably ignore this issue.  I always felt this way, 
but reality is that almost no on cares.  Look at the stats for 
downloading things like movie trailers - even folks on dialup modems, 
when offered different size trailers inevitably pick the largest one, 
even if it is 100MB.  Basically, this issue is less relevant than 
you'd think it should be.

Another alternative, for something like CB is that you could have an 
initial install you'd need to do for any CB app to run, and that 
would be the big one, once that was done, everyone else could just 
have the relatively small bits they need.  It does have the 
disadvantage that an app would not be a single self contained 
package, and I think you'll actually find that folks would prefer 
that, even if it means downloading 5MB instead of 100k.

At the other extreme, I'm also building a static variant of CB and 
associated project templates. An app built with it will be entirely 
self-contained, with its own embedded libperl and all needed 
modules. It actually carries less of a space penalty than I'd 
expected - a static 5.8.0 libperl.a is around 2MB, but once it's 
linked into an app and stripped for size, it's only about 900KB.
In that case, don't even think about trying to build a smaller bundle 
- people in general will not even blink before 10MB these days, and 
in general wont worry about it until it is *much* bigger than that.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: getting $1, $2 etc. in evaled regexp

2003-02-25 Thread Peter N Lewis
eh, is not possible to get the values in parens when you do a reg match on an
evaled string ?
Yes, it is.

consider the snippt below, how do i get the values into $1, $2 etc ...
It'd be easier to explain exactly what you are trying to do.

my $str  = /(.{11})(.{10})/i;
This assigns the result of a regexp search of $_ to $str (probably 
true or false).  Ie, it is equivalent to:

my $str = ($_ =~ /(.{11})(.{10})/i);

It seems unlikely this is what you intend.

my $line  = test string etc  etc test string;
if ($line =~ eval(/ . $str . /)) {
  print id = $1\n;
  print pw = $2\n;
}
I would presume you want something like this:

my $str  = '(?i)(.{11})(.{10})';
my $line  = test string etc  etc test string;
if ($line =~ /$str/ ) {
  print id = $1\n;
  print pw = $2\n;
}
Note the use of the (?i) modifier to turn off case sensitivity inside 
the regexp.  Note that it is needed since your regexp is case 
insensitive anyway.

Chckout:

perldoc perlre

for lost and lots of cool regexp stuff like (?i:regexp) to turn off 
case sensitivity in part of a search and (?:) to bracket without 
creating a $n entry and such.  And then check out the zero length 
assertions for some even cooler stuff.

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: Non-Perl but baffling question

2003-02-25 Thread Peter N Lewis
And, now that I try it, it also looks inaccurate:

% sw_vers | grep 'ProductVersion' | awk '{print $2}'
10.2.4
% osascript -e 'tell application Finder to version'
10.2.1
Not inaccurate as such.  The latter returns the Finder application 
version.  Presumably the former returns the system version.

The Finder version and system version are sometimes in sync but not 
others.  In fact, system 7.0 was the first ever system to ship with 
the Finder and System synced to the same version, before that they 
had always been different and there is no requirement for them to be 
the same.

For example:
% osascript -e 'tell application BBEdit to version'
7.0.2
Sounds like the Finder application has not been updated in the last 
three minor system updates.

You can get the system version like this:

% osascript -e 'tell application Finder to get system attribute sysv'
4132
4132 decimal is 0x1024 (10.2.4)

You can also do this using as shown in Chris Nandor's page at:

http://pudge.net/macperl/yapc/2002/scripts/gestalt

Enjoy,
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: Announcement: PerlPad 0.1

2003-02-09 Thread Peter N Lewis
At 9:51 +0900 10/2/03, Thilo Planz wrote:

Hi all,

I have been playing around with Camelbones a little and placed my 
results on SourceForge:

http://perl-pad.sourceforge.net/

Looks like the compiled binary is locked to perl 5.6, so it doesn't 
work for me with perl 5.8.  I could try to compile it, but I haven't 
tried that yet.

At 23:11 -0500 9/2/03, Sherm Pendley wrote:
None of the Carbon apps I tried - IE, BBEdit, or Mozilla - supported 
it, which is pretty much what I expected. Support for system 
services comes for free in Cocoa, but Carbon programmers have work 
at it - so it's not very surprising that many Carbon apps don't work 
well with them.

BBedit 7.0.1 certainly handles services, which is why I wanted to try 
it to see if I had the same problem with BBEdit - because if so it's 
a problem with perl-pad instead as other services work with BBEdit 7.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: A small Type and Creator weirdness

2003-02-06 Thread Peter N Lewis
At 16:44 -0800 6/2/03, Rich Morin wrote:

I'm using MacOSX::File::Info to get the Type and Creator codes for files.
In trying to print these (e.g., via NSLog and in an NSTextView), I ran
into a peculiar symptom: not only did the code not print, any following
information on the line also disappeared.

After a bit of research, I confirmed that the creator and type methods
were returning a string of four nulls when no real code was available.
This is probably normal behavior in Macland, but it's distinctly non-
Perlish.  Sigh.


File types and creators are arbitrary binary 4 byte numbers.  It is 
only by convention that they are reasonably textish, and also by 
Apple's decree, you can't use creators or types that are all 
lowercase letters unless you're Apple.  They can certainly contain 
weird characters such as control characters and high bit set 
characters.

Also, Perl has no problem with strings containing such characters - 
indeed perl can easily deal with strings that contain four arbitrary 
bytes.  So it is not non-Perlish at all.

It is non-C-ish to treat arbitrary binary data as a string because C 
strings are nul terminated and thus cannot contain zero bytes.

Interestingly, it is also not non-Pascalish because Pascal, like 
Perl, can have arbitrary binary data in strings (although Pascal is 
typically limited to 255 characters in strings, unlike Perl).  This 
is why under traditional Mac OS which was heavily Pascal based, file 
names could have any character, including nul, except colon (:) in 
them, although it was not at all recomended to do such a thing.

So your solution is inadequate.  You probably want to convert any 
bogus characters to perhaps . or ?, eg:

$tmp = $finfo-creator;
$tmp =~ tr/ -~/?/c;

Alternatively, convert it to \123 notation.

$tmp =~ s/([^ -~])/\\.sprintf(%03o,ord($1))/ge;

Enjoy,
   Peter.


Anyway, my workaround was to generate my own string of four nulls,
which I could use to check return values:

  my $null = \000\000\000\000;

  $tmp = $finfo-creator;
  $tmp = '' if ($tmp eq $null);
  row('  Creator', '$tmp');

  $tmp = $finfo-type;
  $tmp = '' if ($tmp eq $null);
  row('  Type', '$tmp');

-r
--
email: [EMAIL PROTECTED]; phone: +1 650-873-7841
http://www.cfcl.com/rdm- my home page, resume, etc.
http://www.cfcl.com/Meta   - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series
http://www.ptf.com/tdc - Prime Time Freeware's Darwin Collection



--
http://www.interarchy.com/  http://download.interarchy.com/



Re: where to put things?

2003-01-16 Thread Peter N Lewis
At 1:07 -0800 16/1/03, Rich Morin wrote:


I then noticed that the script (and any daemons it might start up) was
running as root.  Ungood.  I worked around the problem by setting the
script setuid nobody, but this is not a really robust solution.  I
also filed a bug, suggesting that Apple add a startup parameter (e.g.,
RunAs) that would set the username; the default should be nobody.


In your script, execute the real command using su, eg:

su peter -c '/usr/bin/perl /Users/peter/perl/check-services.pl' 


P.S.  Is there any other documentation to recommend on Startup scripts?


I'd like to hear this one too - I've found that my Startup scripts 
are very unreliable (ie, they seem often to either not execute, or 
execute at the wrong time such that they fail - basically the daemon 
does not end up running after a reboot).  Some detailed info on the 
StartupParameters.plist might be helpful.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Writing a Services plugin in Perl?

2003-01-03 Thread Peter N Lewis
Has anyone written (or know how to) write a Services plugin in Perl?

Perhaps it can be done with CamelBones, but I'd prefer pure perl if 
possible (maybe with some inlines if necessary would be ok).

Thanks,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: No output (Newbie question)

2002-12-16 Thread Peter N Lewis
#! line, permissions on the script, location of perl, etc. seem to 
be ok. But when I try to run a script I get no result. No error 
message, no hello world printed to the terminal. Tried redirecting 
output to a file, but file was empty.

Check the line endings on the file, this is a classic symptom of 
having the wrong line endings such that the entire file looks like a 
single line, all commented out by the leading #
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: closing and opening a browser

2002-12-10 Thread Peter N Lewis
At 13:47 -0800 10/12/02, Adam Wells wrote:


One good way is to use AppleScript for both of these, with the 
osascript command.

The following simple AppleScript will kill Internet Explorer:

-
tell application Internet Explorer
	quit
end tell
-

Not that this is an AppleScript list, but the one line version of 
this is helpful here:

tell application Internet Explorer to quit

(when typing and lazy, application can be shortened to app too).

% osascript -e 'tell application Internet Explorer' -e 'OpenURL 
http://www.example.com;' -e 'end tell'
% osascript -e 'tell application Internet Explorer' -e 'quit' -e 'end tell'

The above is esspecially useful here:

osascript -e 'tell app Internet Explorer to quit'

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/



Re: OT: CVS clients and BBEdit diff tool ...

2002-11-27 Thread Peter N Lewis
BBEdit diff:

I want a bbdiff command-line program. Something that will let me type:

 bbdiff file1 file2

or

 bbdiff dir1 dir2

to initiate a file comparison or multi-file comparison in BBEdit. 
Ideally, Bare Bones would include something like this along side the 
bbedit command-line tool, but I was wondering if anyone has created 
(or could easily create) such a tool via a Perl script making some 
AppleScript calls or something?

bbedit-compare.pl:

#!/usr/bin/perl

use warnings;
use strict;

use File::Spec::Unix;

my $file1 = shift or Usage();
my $file2 = shift or Usage();

compare_in_bbedit( $file1, $file2 );

sub Usage {
  print STDERR Usage: bbedit-compare.pl file1 file2\n;
  exit( 1 );
}

sub compare_in_bbedit {
  my( $file1, $file2 ) = @_;

  $file1 = File::Spec::Unix-rel2abs( $file1 );
  $file2 = File::Spec::Unix-rel2abs( $file2 );

  do_osa_script( EOM );
tell app BBEdit
  compare POSIX file $file1 against POSIX file $file2
  activate
end tell
EOM

}

sub do_osa_script {
  my( $script ) = @_;

  my $fh;
  open( $fh, | /usr/bin/osascript /dev/null ) or die cant open 
osascript $!;
  print $fh $script;
  close( $fh );
}

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: unix or mac-style text files?

2002-11-25 Thread Peter N Lewis
At 13:51 + 25/11/02, Nicholas Clark wrote:

On Mon, Nov 25, 2002 at 02:33:45PM +0100, Rafael Garcia-Suarez wrote:

 Chris Nandor [EMAIL PROTECTED] wrote:
 
  That shouldn't work.  By the time you get to it in the script, 
if you have a
  #! line, then the entire script is one long comment, and the use() line
  won't ever be executed.

 That would be an argument for allowing -M/-m on the #! line.

Er, except that the #! line would all have been read by then, and treated
as a comment. Or have I got things confused?


But is there any reason the # comments are not terminated by the 
first occurrence of *either* \012 or \015?

I can't see how this would affect any perl script, since presumably 
not unix script has a cr hidden in a comment (and similarly for Mac 
script and lf), and even for DOS, the cr will terminate the comment 
and the lf will be an irrelevant  white space (comments can't be 
inside anything that is storing white space, right?)

This would solve the #! commenting out the entire file issue, and 
allow the -M flag on the #! line to work.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: unix or mac-style text files?

2002-11-25 Thread Peter N Lewis
At 15:09 +1100 26/11/02, Ken Williams wrote:

On Tuesday, November 26, 2002, at 12:49  PM, Peter N Lewis wrote:



But is there any reason the # comments are not terminated by the 
first occurrence of *either* \012 or \015?

There's nothing perl can do about this - the OS (in fact, the 
kernel, I think) reads that shebang line in order to know it should 
call perl.  By the time perl gets to look at it, it's too late.

Ahh, yes, good point.

Except - the shell reads the file and executes the program that is 
the first word after the #! so perl will indeed get called for a file 
with the wrong line endings, although it might get called with the 
entire file inserted into the ARGV.  But then perl does all sorts of 
wacky emulation at that point anyway, so don't ask me what goes on 
there, I couldn't figure it out.

For example, a file containing

#!/bin/ps auxw

when executed does the ps with those flags.

A file containing

#!/bin/echo -e 'foreach (@ARGV) { print $_\n; }'
blah blah blah

displays 'foreach (@ARGV) { print $_\n; }'

But a file containing

#!/usr/bin/perl -e 'foreach (@ARGV) { print $_\n; }'
foreach (@ARGV) { print $_\n; }

displays nothing, presumably because of perl doing some wacky 
emulation on the command line.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: No bell

2002-11-21 Thread Peter N Lewis
At 9:42 + 21/11/02, John Delacour wrote:

Now why don't I get a bell but when I do ( print \a ) or ( print 
\007 ) in 10.2.2/Perl5.8.0?  It works fine in MacPerl and no 
character is printed but in OS 10 the only way I've found is:

 $/ eq \015 and `osascript -e beep` ;

which slows things down a lot.

Remember, with perl, There Is More Than One Way To Do It.

Just forget about printing the bell character and hoping whoever is 
listening will do something, instead, beep yourself:


#!/usr/bin/perl -w
use strict;
use Inline  C = 'DATA',
LDDLFLAGS = '-bundle -flat_namespace -undefined suppress 
-framework Carbon',
INC   = '-I/Developer/Headers/FlatCarbon';

beep();

__END__
__C__
#undef Move
#include Sound.h
void beep()
{
SysBeep( 1 );
}


I take no claim of cleverness on this solution, it is copied directly 
from Chris Nandor's gestalt example, especially the required #undef 
Move.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: unix or mac-style text files?

2002-11-20 Thread Peter N Lewis
At 13:22 + 20/11/02, John Delacour wrote:


 if (/\015\012/) {
  $/ = \015\012 ;
 } elsif (/\015/) {
   $/ = \015 ;
 } else {
   $/ = \012 ;
 }


You can do this with one regular expression which will pick up the 
first line ending:

 $/ = /(\015\012|\015|\012)/ ? $1: \n;

Note that because Perl picks the first match location, and after that 
picks the first of an or | set, it will find the first location, 
and will find the \015\012 if it is there in preference to the \015 
by itself.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: unix or mac-style text files?

2002-11-19 Thread Peter N Lewis
At 16:30 -0800 19/11/02, Heather Madrone wrote:

I've already encountered a few text file anomalies on OS X. Most GUI 
applications seem to default to Mac-style text files (linefeeds 
only), but shell programs such as vi do not handle Mac-style text 
files gracefully.

Is perl on the Mac going to care whether source files are Mac-style 
or Unix-style?
Is it going to have difficulty reading and operating on either kind 
of file?  What kind of text files will it write?

Thanks in advance for any illumination.

Definitely read the perlport section of the documentation at:

http://www.perldoc.com/perl5.6.1/pod/perlport.html

Traditionally on Mac OS, line endings have been carriage return (cr) only.

Unix uses just linefeed line (lf) endings.

DOS/Windows uses carriage-linefeed (crlf) line endings.

Under Mac OS X, it is quite schizophrenic - some applications with 
handle only Mac line endings, some applications handle only Unix line 
endings, some applications will handle Unix or Mac (or even DOS) line 
endings.

Ignoring MacPerl (running under Mac OS X), and looking only at Mac OS 
X's /usr/bin/perl (or wherever you've installed perl), which is a 
Unix perl, not a Mac perl, we have:

Perl source files must have Unix line endings (lf only).  If the 
source file has Mac line endings, then it will usually run and do 
absolutely nothing (if you run it as perl script.pl, or it will 
complain script.pl: Command not found. if you run it as 
../script.pl.  This is because the first line is #!/usr/bin/perl - but 
after that the cr is not a line ending and so the entire source file 
appears as a single line.  If you run it with perl, then it will 
ignore the entire file as a comment.  If you run it yourself, then it 
will try to use the entire file as a command and wont be able to find 
/usr/bin/perlcrcruse (for example) as a command to run.

By default, Perl will read and write unix line ending files.  You can 
change the input separator with $/ = \r for Mac line endings, 
\r\n for DOS line ending (and back to \n for Unix, although 
saving and restoring is better practice) .  You can change the output 
by just printing the appropriate line ending.  In this case, a nice 
practice might be to do:

our $eol = \015\012; # Windows line ending

print First Line$eol;

My suggestion for Mac OS X users is to switch to using Unix line 
endings as soon as possible, and wherever possible support reading 
files with any line ending.  One simple thing I almost always do is:

while () {
  s/\015?\012$//; # instead of chomp
}

Yes, chomp is probably faster, but most of the time it makes no 
difference.  Not that the above code will not help you with Mac files 
because the  will read the entire file in one go :-(

It's really unfortunate that there is no special case value for $/ 
(like  perhaps) that handles \015\012|\015|\012 as a line ending. 
There is talk of making $/ a regex which would allow that, but that's 
huge overkill just to handle this one particular very special case.

An alternative is to read the entire file in (undef $/) and then split it:

local( $/ ) = undef;
my $file = ; # read in entire file
my @lines = split( /\015\012|\015|\012/, $file );
foreach my $line (@lines) {
  print '$line'\n;
}

Which is ok, but not great for big files.

Enjoy,
   Peter.


--
http://www.interarchy.com/  http://download.interarchy.com/


Re: unix or mac-style text files?

2002-11-19 Thread Peter N Lewis
At 19:01 -0800 19/11/02, gene wrote:

An alternative is to read the entire file in (undef $/) and then split it:


My suggestion is to put some code like this in your script:


It's a good solution.  Probably for files less than a few hundred k 
it makes no difference (since you'll need to read the entire file 
anyway, until the memory usage of storing the whole thing becomes an 
issue it wont affect anything).

For portability, you should use \012 and \015 explicitly, except for 
the final default value which should be \n.  Here is the code, with 
the fail counter added to avoid it reading forever in a file with no 
line endings (not that it is likely to help anyway since you'll 
presumably follow this up with reading a line...)

# Usage: local $/ = get_line_ending($fh);
# By gene

sub get_line_ending {
  my ($fh) = @_;

  my $failcount = 33000;
  my $char;
  while (read $fh, $char, 1 and $failcount--  0) {
if ($char eq \012) {
  seek $fh, 0, 0;
  return \012;
} elsif ($char eq \015) {
  if (read $fh, $char, 1 and $char eq \012) {
seek $fh, 0, 0;
return \015\012;
  } else {
seek $fh, 0, 0;
return \015;
  }
}
  }
  ## what, no line ending?
  ## return a reasonable default
  seek $fh, 0, 0;
  return \n;
}

Suggestions for the above code:
Move the sub into a module.


I have ;-).  whether it's worth publishing a CPAN module, I don't 
know.  Perhaps adding it to some existing module?

I assume it's more efficient to read small chunks of bytes rather
than byte by byte.  For most text files this shouldn't matter, but
you may want to alter the reads and also the comparisons if you care.


It would require some timing to figure out if reading a block of 
characters would be better, possibly something like:

read 256 characters, look for the first \012 or \015 and see what's 
up (being careful not to accept a \015 as the 256th character as an 
answer), then try again with a larger read

would be more efficient, but then again, possibly not.  It would 
depend on a lot of things and might vary from OS to OS, so it's 
probably not worth worrying too much about.

Enjoy,
   Peter.


--
http://www.interarchy.com/  http://download.interarchy.com/


Re: PerlMagick dyld errors

2002-11-17 Thread Peter N Lewis
If you do ensure your fink Trees: has the unstable/main in it, and do:

fink selfupdate-cvs

then I think it will install imagemagick-nox for you without any problems.

Unfortunately, perlmagick-pm still seems to be a version of 
imagemagick back and so it needs to be installed manually.

Anyway, looks like it's getting closer!
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: Darwin darwin or darwin6.0

2002-11-17 Thread Peter N Lewis
At 11:39 -0800 16/11/02, drieux wrote:


[jeeves: 1:] perl -MConfig -e 'print $Config{osname} \n; '



As for how this gets set - it gets set when your version of perl
is built for that specific OS.


which in turn is stored in Config.pm, typically somewhere like 
/Library/Perl/darwin/Config.pm or System/Library/Perl/darwin/Config.pm

this can be handy if you need to correct any settings (such as 
library or include paths).

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: OS X Installed numbers (Was Re: mac-toolbox)

2002-11-15 Thread Peter N Lewis
At 7:58 -0500 15/11/02, [EMAIL PROTECTED] wrote:

Well, I for one, use Maya from SGI|Alias|Waefront - and it doesn;t 
support 10.2 - there are a number of dialog boxen which get very 
screwed up by it.

Are there any other packages which work under 10.1-  not in 10.2+ ?

Yes, there have been quite a number of programs with problems under 
10.2, I don't have any particular gotchas, but lots of programs 
required updating for 10.2.

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: BBEdit 7.0

2002-11-13 Thread Peter N Lewis
At 14:18 -0500 13/11/02, John Siracusa wrote:

On 11/13/02 11:46 AM, Adrian Howard wrote:

 And CVS support too! Excellent!


Hrm, not so excellent for me so far...it just hangs with the connecting
dialog box and then fails.  CVS works fine from the command line.  Maybe
BBEdit isn't picking up my CVS environment variables?  I thought there'd be
someplace to set them in the BBEdit prefs, but I haven't found it yet...


Where are your environment variables configured?

For BBEdit to have them, they probably need to be in:

~/.MacOSX/environment.plist

Which needs to be something like:


?xml version=1.0 encoding=UTF-8?
!DOCTYPE plist SYSTEM file://localhost/System/Library/DTDs/PropertyList.dtd
plist version=0.9
dict
keyCVSROOT/key
stringyourusernameyourhost:/cvs/string
keyCVS_RSH/key
stringssh/string
keyDISPLAY/key
stringlocalhost/string
keyLC_ALL/key
stringC/string
keyPERL5LIB/key
string/Library/Perl:/Users/yourusername/perl/string
/dict
/plist


Changes take effect at login, so you'll need to logout and log back in.

From what I've seen, there are three places you can put environment variables:

~/.MacOSX/environment.plist - used by everything you launch directly.

~/.cshrc or ~/.tcshrc - used by any tcsh shell you launch (including 
remotely accessed ones).  Terminal launched ones probably pick up the 
environment.plist variables, but if you ssh into your Mac from 
another Mac, then probably not.
setenv PERL5LIB /Library/Perl:/Users/yourusername/perl
setenv CVSROOT yourusernameyourhost:/cvs
setenv CVS_RSH ssh
setenv LC_ALL C

crontab -e file - you can also set envrionment variables in your 
crontab which will get used when executing cron actions.
PERL5LIB=/Library/Perl:/Users/yourusername/perl
LC_ALL=C
12 1 * * * perl dosomething.pl

Enjoy,
   Peter.


--
http://www.interarchy.com/  http://download.interarchy.com/


Re: BBEdit 7.0

2002-11-13 Thread Peter N Lewis
Yeah, I considered that, but I figured it'd be mentioned somewhere in the
BBEdit docs if I had to go to that length.  Anyway, BBEdit appears to try to
contact the correct server, which leads me to believe it is reading my
config (or at least some of it).  Or is the hostname in the CVS/ directories
somewhere?  Anyway, I'll try futzing with environment.plist tomorrow...


Yes, once you setup a CVS directory, it no longer needs the CVS ROOT 
(it is in ./CVS/Root  ./CVS/Repository.  You still need the CVS RSH 
setting though, at least if you want it to go through ssh.

(Disclosure triangles? Possibly Anarchie 4.0 --Peter N Lewis, 12/99)
(glad to see they finally made it ;)


Yeah, must be one of those features we've run out of, or maybe 
something not too difficult we could implement ;-)
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: PerlMagick dyld errors

2002-11-12 Thread Peter N Lewis
Sigh, here is yet another account of making ImageMagick and Perl work.

I just upgraded to 10.2.  So I cleaned out my perl installation and 
installed perl 5.8 (ok, so this is living a bit on the edge).

To get ImageMagick working I did this:

fink install imagemagick-nox

sadly it could not find the .tar.gz file, so I downloaded it and 
placed it in a directory and reconfigured fink so it would look for 
files in that directory and tried again:

fink install imagemagick-nox

sadly, this depends on ghostscript which depends on X, so I hacked 
the .info file:

/sw/fink/10.2/unstable/main/finkinfo/graphics/imagemagick-nox-5.5.1-2.info

to replace ghostscript with ghostscript6-nox and tried again:

fink install imagemagick-nox

ok, now imagemagick is installed, off to get it working with perl:

 2) fink list imagemagick
 3) Note the version number (n.n.n-n) by the version you have installed.
 4) cd; mkdir Build; cd Build (getting to a scratchdir)
 5) tar xvfz /sw/src/ImageMagick-n.n.n.tar.gz; cd Image*/PerlMagick/
 5.5) edit Makefile.PL so that
   LIBS begins with -L/sw/lib and INC begins with -I/sw/include
 6) perl Makefile.PL; make all install


Did that, but then it was giving me lots of dylb errors for jpeg, 
tiff, bz2, png, xml2.

So I added -ljpeg -ltiff -lbz2 -lpng -lxml2 to the LIBS in 5.5 above:

make clean; perl Makefile.PL; make all;
sudo rm -rf /Library/Perl/darwin/auto/Image/Magick
sudo make install

and now it seems to be working again.

Hopefully this might save someone a few hours of mucking around.

Looking forward to the day when fink install imagemagick-nox; fink 
install perlmagick is all that is required...

Enjoy,
   Peter.

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: segmentation fault when searching for repeated text

2002-11-12 Thread Peter N Lewis
The following code ends up with an error (segmentation fault):

	$_ = 'x' x 1000;
	/(a.|.){2,}/o;

The segmentation fault seems to happen only when the searched text 
($_ in this example) is longer than 855 characters.

I know that m and n in the {m,n} qualifier are limited, but there 
isn't a limitation for the length of the searched text, is there?

I'm using Perl 5.6.0 built for Darwin.

Yep, the same thing happens in perl 5.8.0 under Mac OS X 10.2.1, 
except it happens when it is longer than 927 characters.

Looks like quite a robust bug.  I wonder if it is even Mac OS X specific.
   Peter.
--
http://www.interarchy.com/  http://download.interarchy.com/


Re: ImageMagick, PerlMagick, and OSX web server

2002-11-04 Thread Peter N Lewis
At 11:42 -0600 4/11/02, Bill Stephenson wrote:

Thanks Randal! I've wanted to play with PerlMagick for years. I've played
with ImageMagick but never got PerlMagick installed. I'm gonna have to try
it our now.


It is quite amazing.  I had a really old newsletter that I want'ed to 
make available, so I scanned in each page in to a folder of .gif 
images, and then wrote a perl script (below) using ImageMagick to 
pack them together in to a PDF - worked like a charm.

Very cool!
   Peter.

use Image::Magick;

use warnings;
use strict;

my $dir = '/Users/peter/3.2.out';
my $pdffile = '/Users/peter/3.2.pdf';

chdir( $dir ) or die Cant chdir to $dir $!;
while( *.gif ) {
  push files, $_;
}

my $pdf = Image::Magick-new();

foreach $file ( sort files ) {
  my $img = Image::Magick-new();
  $rc = $img-Read( $file );
  warn $rc if $rc;
  push $pdf, $img;
}

$pdf-[0]-Coalesce();
$pdf-Write( $pdffile );

--
http://www.interarchy.com/  http://download.interarchy.com/


Re: Why is 27 special?

2002-10-10 Thread Peter N Lewis

At 3:09 -0500 10/10/02, _brian_d_foy wrote:

this means that the 20 fixed bytes between the volume name and the date,
which are \000 in every case i looked at, is really 27 - (length of volume
name).  i can name partitions with names up to 27 characters, but if i go past
that it look like it initially works but then gives a warning. 
what's the deal?
what is magic about 27?  why not 31?  i assume that these are C 
strings somewhere
so the null bytes makes them a nice, even number.

Mac volume names are limited to 27 characters.  See

http://developer.apple.com/techpubs/mac/Files/Files-102.html

for a description for the Master Directory Blocks (aka volume 
information block).  If I had to guess, I'd say that the volume name 
was intended to be 31 characters, and then at the last minute the 
volume backup date field was added in at the end of the name which 
reduced the length of the volume name from 31 to 27 characters.

Enjoy,
Peter.

-- 
I was away for two months and have just returned, and now have
4600 messages to wade through, so sorry for any delays.
http://www.interarchy.com/  http://download.interarchy.com/



Re: about .command and .term

2002-07-15 Thread Peter N Lewis

At 16:20 -0600 14/7/02, Charles Albrecht wrote:

I use .term files by editing the ExecutionString value in
the XML to have...

 keyExecutionString/key
 stringssh foo.bar.baz; exit/string

behave as I want it to behave.

Furthermore, I toss frequently-used .terms into
~/Library/Application Support/Terminal

to have them appear on Terminal's submenu (for these - particular
the ssh variety - I also tend to edit the CustomTitle parameter
to keep them clear by their titles.

Wow!  That is so excellent!  Amazing what you learn on this list!

Thanks!
Peter.
PS: And I double checked it really was Charles who wrote this.

-- 
http://www.interarchy.com/  http://download.interarchy.com/



Re: cpan oddness

2002-07-03 Thread Peter N Lewis

At 14:33 -0400 3/7/02, Sherm Pendley wrote:

Judging by the path displayed here, you were a little quick on the 
trigger, and answered 'y' when the configuration requsted a 
pathname. Don't feel bad, it's happened before - check the list 
archives. :-)

Hmmm, if it has happened before, perhaps it would be good to put a 
check in for this case in the configuration program and put up a nice 
big flashing warning Are you really sure you want this path set to 
'y'?.

It could just be my Mac heritage showing though ;-)
Peter.

-- 
http://www.interarchy.com/  http://download.interarchy.com/



Re: Serial ports?

2002-06-24 Thread Peter N Lewis

At 9:39 + 24/6/02, Tor Hildrum wrote:

   Somewhere around test 85 the Mac crashes badly.  Even from user mode.

That is strange. The kernel shouldn't really panic, unless you where running
this process in kernel space. Trying to access an I/O port or
hardware-mapped memory shouldn't give you a kernel panic from user space.
The kernel should just reject it, and send a signal to your process.

Yeah, that was my thoughts!

I think you have to use a device driver.
Or you need to make your script run in kernel space, you can't access any HW
from user space.

Yes and no.  You're right, I didn't have a driver, the Belkin serial 
ports aren't supported under Mac OS X, so there was in fact no serial 
port available at all.

This still begs the question how can a user process running the Perl 
Device::Serial test scripts completely crash the Mac.  But at the end 
of the day, it isn't going to work anyway because I don't have any 
serial ports (I was confused because I can actually access the serial 
ports as USB devices under Virtual PC from Windows!).

On another Mac with a built in serial port I am just reading/writing 
from /dev/cu.modem and it is working fine.
Peter.
-- 
http://www.interarchy.com/  http://download.interarchy.com/



Re: FYI: Successful Install of Perl 5.8.0 RC 1 + Apache 2.0.36 + ModPerl-2.0 on OSX 10.1.4

2002-06-04 Thread Peter N Lewis

At 14:05 -0700 4/6/02, Alex S wrote:
I'd prefer to see if we could convince the developers at Apple to 
use a better file system.  I'm hoping that one of the new people on 
the core Apple dev team (forget his name at the moment), who is a 
filesystems guy, is there to make that all better!  A journalled FS 
would be nice too.

If you want a more general solution than Perl changing the name of 
the files to *.txt (which would mnake sense anyway as someone else 
pointed out), then i think  changing make is far more likely than 
changing Apple's file system.  What about updating make to deal with 
the difference between a file called INSTALL and a tag install rather 
than just blindly using the file system.

According to the man file for gnumake:

make  executes  commands  in the makefile to update one or
more target names, where name is typically a program.   If
no  -f option is present, make will look for the makefiles
GNUmakefile, makefile, and Makefile, in that order.

Nothing is mentioned about what the target an be, I guess the idea is 
you can do make file.o and have it figure out to compile the .c 
file?

Heck, even a special case for install/INSTALL would resolve a lot of 
problems - perhaps even just a special build for Mac OS X that dealt 
with the issue.

Expecting a case sensitive file system by default out of Apple any 
time soon is a bit of a wish - beside, Mac OS still uses all the meta 
data stuff that HFS provides that other file systems do not generally 
provide.  As for UFS, I've heard of lots of people having Mac OS 
related problems with that (ie, the file system works fine, but the 
applications don't).
Peter.
-- 
http://www.interarchy.com/  http://download.interarchy.com/



Re: Native graphics support?

2002-05-16 Thread Peter N Lewis

At 19:08 -0700 15/5/02, The Ogre wrote:
Ok, I'm close to giving up, and that's not like me... If there's more
than one way to do it, please somebody show me one...

OroborOSX over XDarwin seems to be the closest approximation I've found.

Please, a ray of light, I beg of you. They can do it in C++, Java, TCL,
and even Python (shudder) - we *must* be able to do it in perl, right?

I couldn't figure it out for Python either.

I'd love to have an answer to this!
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: puzzling results from missing she-bang

2002-04-28 Thread Peter N Lewis

At 22:09 -0400 28/4/02, Michael  Turner wrote:

Thanks for your response. I remain puzzled, however. Your response 
seems to imply that if I invoke print from the command line, it 
will be interepreted. This is not the case, it errors.

Sure it will - if you are using the sh shell.  Try this:

zany:~/unix/avr/avr/include% sh
zany% print hello;
hello
zany% exit
zany:~/unix/avr/avr/include%

(ie, type: shreturnprint hello;return)

Enjoy,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: Permanently add INC directory? - summary

2002-04-23 Thread Peter N Lewis

Is there any way to globally add an INC directory to Perl after compilation?

But it doesn't get set when I run Perl from within BBEdit or cron. 
Is there any way to do this so it is truly global (it can just be 
across me as the user or for all users, since I'm the only user 
anyway, as long as that will work with things like BBEdit and cron).

[I did not want to add it to every script because I want my scripts 
to be machine independent and my system to define where the libraries 
are at]

Answer 1 from Dan Kogai  Jerry Levan:

Add the line:
push INC , /my/custom/path;
or better:
use lib '/my/custom/path';
to the start of all affected scripts.

This works everywhere, but you have to add this in to each perl script.

You could use the FindBin module to make it based on where the script 
is which would improve it, but it does add a bunch of guf at the 
front of each script.

Answer 2:

add the line
setenv PERL5LIB /my/custom/path
to your .cshrc

This works from scripts run from the terminal, but not from BBEdit or cron.

Answer 3 from David Wheeler  Rick Frankel:

You can get set PERL5LIB in ~/.MacOSX/environment.plist. When you set 
environment variables there, they are set for the OS X GUI as well
as for the shell, so it'll work in BBEdit, for example.

?xml version=1.0 encoding=UTF-8?
!DOCTYPE plist SYSTEM
file://localhost/System/Library/DTDs/PropertyList.dtd
plist version=0.9
   dict
 keyPERL5LIB/key
 string/my/custom/path/string
   /dict
/plist

This does not work in cron, and apparently there is a slight overhead 
to using environment variables.  You must logout and log back in for 
this to take effect.

Answer 4 from Rick Frankel:

For cron, you can set environment variables in the crontab, just add the line:
PERL5LIB=/my/custom/path
to the start of the crontab - or better yet, use the CronniX 
application and configure the Environment variables via the menu 
command.

So essentially, you could use Answer 1, or all of Answers 2, 3 and 4.

Enjoy,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: imagemagick, fink, versions, ick.

2002-04-18 Thread Peter N Lewis

after a few false starts, i've got imagemagick working, or rather fink has.
i was initially reluctant to install all the bits of X11 that it 
insists on, but while i succeeded in installing imagemagick from 
source, i could never get it to link to fink's libjpeg. so i've 
stopped fighting it and now it's working perfectly, from the command 
line at least.

Yeah, this is what mucked me around before (see my post below on how 
I got around it, eventually).

problem is, the version of PerlMagick i installed before is more up 
to date than Fink's imagemagick, and seems to be upset. IM is 
finally working on jpegs, but i can't get at it with perl any more :(

One possibility is to rebuild your location database, do a locate 
Magick and then just delete everything in your installed directories 
that match and start again (worked for me anyway).  You might want to 
ask fink to uninstall it first and then just use the above technique 
to get rid of any stragglers.

Fun fun fun,
Peter.


Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
List-Post: mailto:[EMAIL PROTECTED]
List-Help: mailto:[EMAIL PROTECTED]
List-Unsubscribe: mailto:[EMAIL PROTECTED]
List-Subscribe: mailto:[EMAIL PROTECTED]
Mime-Version: 1.0
X-Sender: peter@pop
Date: Fri, 12 Apr 2002 17:07:11 +0800
To: MacOSX Perl [EMAIL PROTECTED]
From: Peter N Lewis [EMAIL PROTECTED]
Subject: Getting ImageMagick/PerlMagick to work

Hi all,

I finally got ImageMagick to install and work for me, perhaps this 
will help someone else...

I think pert of the problem might be that I have perl 5.6.1 installed.

Anyway, I eventually got it to install by using fink, but then it 
failed because it wanted _ParseGeometry, which I think is some sort 
of X windows thing, so I rebuilt it using:

fink fetch imagemagic

edit 
/sw/fink/dists/stable/main/finkinfo/graphics/imagemagick-5.4.1-3.patch 
and add a line to disable X windows support (add the line with_x=no, 
and change the 27 to 28 on the first line of the patch hunk).

@@ -7720,6 +7720,28 @@
  # FIXME: insert proper C++ library support
  ld_shlibs_CXX=no
  ;;
+  darwin* | rhapsody*)
+case $host_os in
+rhapsody* | darwin1.[012])
+  allow_undefined_flag_CXX='-undefined suppress'
+  ;;
+*) # Darwin 1.3 on
+  allow_undefined_flag_CXX='-flat_namespace -undefined suppress'
+  ;;
+esac
+with_x=no
+
+# FIXME: Relying on posixy $() will cause problems for
+#cross-compilation, but unfortunately the echo tests do not
+#yet detect zsh echo's removal of \ escapes.  Also zsh mangles
+#`' quotes if we put them in here... so don't!
+archive_cmds_CXX='$CC $(test .$module = .yes  echo -bundle || 
echo -dynamiclib) $allow_undefined_flag -o $lib $libobjs 
$deplibs$linker_flags -install_name $rpath/$soname $verstring'
+# We need to add '_' to the symbols in $export_symbols first
+#_LT_AC_TAGVAR(archive_expsym_cmds, 
CXX)=$_LT_AC_TAGVAR(archive_cmds, CXX)'  strip -s $export_symbols'
+hardcode_direct_CXX=yes
+hardcode_shlibpath_var_CXX=no
+whole_archive_flag_spec_CXX='$convenience'
+;;
aix4* | aix5*)
  if test $host_cpu = ia64; then
# On IA64, the linker does run time linking by default, so we don't


After that just continue with the install

fink build imagemagic
fink install imagemagic

(you might have to do the build/install first to generate the patch 
file in the first place, I don't know where it came from).

Also, I found that new Image::Magick didn't work, but 
Image::Magick-new does.  This code now works for me:

use Image::Magick;

$image=Image::Magick-new;
$x = $image-Read( filename='/Users/peter/unix/game-org.jpg' );
warn $x if $x;
$x = $image-Resize( geometry='640x480' );
warn $x if $x;
$x = $image-Write( filename='/Users/peter/unix/game-out2.jpg', quality=75 );
warn $x if $x;
$x = $image-Resize( geometry='64x48' );
warn $x if $x;
$x = $image-Write( filename='/Users/peter/unix/game-out2.gif' );
warn $x if $x;
@$image = ();

Which is pretty cool if you want to generate web images or thumbs 
from large originals for example...

Hope this is useful.  Won't it be nice in a year or so when all this 
stuff just works out of the box!
Peter.
--
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Getting ImageMagick/PerlMagick to work

2002-04-12 Thread Peter N Lewis

Hi all,

I finally got ImageMagick to install and work for me, perhaps this 
will help someone else...

I think pert of the problem might be that I have perl 5.6.1 installed.

Anyway, I eventually got it to install by using fink, but then it 
failed because it wanted _ParseGeometry, which I think is some sort 
of X windows thing, so I rebuilt it using:

fink fetch imagemagic

edit 
/sw/fink/dists/stable/main/finkinfo/graphics/imagemagick-5.4.1-3.patch 
and add a line to disable X windows support (add the line with_x=no, 
and change the 27 to 28 on the first line of the patch hunk).

 -7720,6 +7720,28 
  # FIXME: insert proper C++ library support
  ld_shlibs_CXX=no
  ;;
+  darwin* | rhapsody*)
+case $host_os in
+rhapsody* | darwin1.[012])
+  allow_undefined_flag_CXX='-undefined suppress'
+  ;;
+*) # Darwin 1.3 on
+  allow_undefined_flag_CXX='-flat_namespace -undefined suppress'
+  ;;
+esac
+with_x=no
+
+# FIXME: Relying on posixy $() will cause problems for
+#cross-compilation, but unfortunately the echo tests do not
+#yet detect zsh echo's removal of \ escapes.  Also zsh mangles
+#`' quotes if we put them in here... so don't!
+archive_cmds_CXX='$CC $(test .$module = .yes  echo -bundle || 
echo -dynamiclib) $allow_undefined_flag -o $lib $libobjs 
$deplibs$linker_flags -install_name $rpath/$soname $verstring'
+# We need to add '_' to the symbols in $export_symbols first
+#_LT_AC_TAGVAR(archive_expsym_cmds, 
CXX)=$_LT_AC_TAGVAR(archive_cmds, CXX)'  strip -s $export_symbols'
+hardcode_direct_CXX=yes
+hardcode_shlibpath_var_CXX=no
+whole_archive_flag_spec_CXX='$convenience'
+;;
aix4* | aix5*)
  if test $host_cpu = ia64; then
# On IA64, the linker does run time linking by default, so we don't


After that just continue with the install

fink build imagemagic
fink install imagemagic

(you might have to do the build/install first to generate the patch 
file in the first place, I don't know where it came from).

Also, I found that new Image::Magick didn't work, but 
Image::Magick-new does.  This code now works for me:

use Image::Magick;

$image=Image::Magick-new;
$x = $image-Read( filename='/Users/peter/unix/game-org.jpg' );
warn $x if $x;
$x = $image-Resize( geometry='640x480' );
warn $x if $x;
$x = $image-Write( filename='/Users/peter/unix/game-out2.jpg', quality=75 );
warn $x if $x;
$x = $image-Resize( geometry='64x48' );
warn $x if $x;
$x = $image-Write( filename='/Users/peter/unix/game-out2.gif' );
warn $x if $x;
$image = ();

Which is pretty cool if you want to generate web images or thumbs 
from large originals for example...

Hope this is useful.  Won't it be nice in a year or so when all this 
stuff just works out of the box!
Peter.
-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: [Fink-users] Re: is my perl tarnished?

2002-04-03 Thread Peter N Lewis

At 18:31 -0600 3/4/02, Chris Devers wrote:

So is it Storable.pm that's corrupted? Think it'll help to rebuild it?

I have some memory of reading something where Storable was used with 
a lowercase s, and so it was loaded (successfully, because of the 
case insensitivity) and then not found next time.

Unfortunately, I can't find where I read this now.

Also, when I had those dylb problems, it turned out the problem was 
in my library path settings.  You might want to do a perl -V and 
compare it to the output below and check out any differences, 
particularly any in the paths.

Enjoy,
Peter.



zany:~/unix% perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
   Platform:
 osname=darwin, osvers=5.3, archname=darwin
 uname='darwin zany.peter.com.au 5.3 darwin kernel version 5.3: 
thu jan 24 22:06:02 pst 2002; root:xnuxnu-201.19.obj~1release_ppc 
power macintosh powerpc '
 config_args='-des -Dfirstmakefile=GNUmakefile -Dldflags=-flat_namespace'
 hint=recommended, useposix=true, d_sigaction=define
 usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
 useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
 use64bitint=undef use64bitall=undef uselongdouble=undef
   Compiler:
 cc='cc', ccflags ='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-aliasing -I/usr/local/include',
 optimize='-O3',
 cppflags='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE 
-fno-strict-aliasing -I/usr/local/include'
 ccversion='', gccversion='Apple devkit-based CPP 6.02', gccosandvers=''
 intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
 ivtype='long', ivsize=4, nvtype='double', nvsize=8, 
Off_t='off_t', lseeksize=8
 alignbytes=8, usemymalloc=n, prototype=define
   Linker and Libraries:
 ld='cc', ldflags ='-flat_namespace -L/usr/local/lib'
 libpth=/usr/local/lib /usr/lib
 libs=-lm -lc
 perllibs=-lm -lc
 libc=/System/Library/Frameworks/System.framework/System, 
so=dylib, useshrplib=true, libperl=libperl.dylib
   Dynamic Linking:
 dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
 cccdlflags=' ', lddlflags='-flat_namespace -bundle -undefined 
suppress -L/usr/local/lib'


Characteristics of this binary (from libperl):
   Compile-time options: USE_LARGE_FILES
   Built under darwin
   Compiled at 03/25/02 16:24:31
   %ENV:
 PERL5LIB=/Users/peter/perl/Lib
   INC:
 /Users/peter/perl/Lib
 /System/Library/Perl/darwin
 /System/Library/Perl
 /Local/Library/Perl/darwin
 /Local/Library/Perl
 /Local/Library/Perl
 /Network/Library/Perl/darwin
 /Network/Library/Perl
 /Network/Library/Perl
 .
zany:~/unix%

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: CPAN problems? dyld: perl Undefined symbols?

2002-03-25 Thread Peter N Lewis

At 11:28 +0800 21/3/02, Peter N Lewis wrote:

But when I try to use CPAN, I get these errors:

cpan install Bundle::CPAN
dyld: perl Undefined symbols:
_PerlIO_getc
_PerlIO_putc
_PerlIO_read
_PerlIO_write
_Perl_sv_2pv_flags

Ok, it turns out my problem was either my library path or not running 
perl -MCPAN -e shell as root.

I reinsalled a completely clean 5.6.1 with

../Configure -des -Dfirstmakefile=GNUmakefile -Dldflags=-flat_namespace
make
make test
mv INSTALL INSTALL.txt
sudo make install

And things seem to be working.

Thanks particularly to Rick Frankel who gave me the clue I needed to 
reinstall 5.6.1 properly.

Thanks,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



CPAN problems? dyld: perl Undefined symbols?

2002-03-20 Thread Peter N Lewis

I've installed perl 5.6.1, and I just did an install of CPAN 1.59 from

http://www.cpan.org/authors/id/A/AN/ANDK/CPAN-1.59.tar.gz

But when I try to use CPAN, I get these errors:

cpan install Bundle::CPAN
dyld: perl Undefined symbols:
_PerlIO_getc
_PerlIO_putc
_PerlIO_read
_PerlIO_write
_Perl_sv_2pv_flags

How can I fix that?  I saw something about dyld: perl Undefined 
symbols before and the solution was to remove -static from the 
Makefile, but CPAN's Makefile doesn't have -static anywhere.  I tried 
changing LINKTYPE from dynamic to static, but that didn't have any 
effect.

Ok, so then I thought perhaps I had some confusion about which 
modules where installed.  So I removed /System/Library/Perl and 
reinstalled perl 5.6.1.  Still the same thing happens.

What am I missing?

Thanks,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Newline independence?

2002-02-17 Thread Peter N Lewis

Is there any good way to read a file in a way that is independent of 
the newlines used in that file?

Mac typically uses CR line endings.  Unix typically uses LF line 
endings.  And DOS  Network (eg HTTP, FTP, etc) typically use CRLF 
line endings.

Ideally, it would be possible to set $/ to something such that Perl 
would just do the right thing (when using EXPR), but this does not 
seem to be possible.  Reading:

http://www.perldoc.com/perl5.6/pod/perlport.html#Newlines

is no use.  It has the standard trick of using CR or LF and then 
stripping out the other one to hand CR  CRLF or LF  CRLF, but that 
trick does not work in the unfortunately now common case on Mac OS X 
of having to deal with both CR  LF.

Short of writing my own readline function, of pre-reading a file and 
then figuring out the line ending, I can't think of any good/easy way 
to handle reading a text file that might have either CR or LF line 
endings.  Does anyone know a good trick?

Thanks,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx



Re: Applescript call from Perl

2002-02-07 Thread Peter N Lewis

At 21:13 -0500 7/2/02, Brad Rice wrote:
How do you call Applescript from Perl? I want to make a CGI that 
runs an applescript.

In MacPerl, use:

MacPerl'DoAppleScript(END_SCRIPT);
tell application Finder
move alias $folder to trash
end tell
END_SCRIPT

I believe MacPerl can also do raw AppleEvents.

In Mac OS X Perl, use /usr/local/bin/osascript, man osascript for 
info on how to use it and send the data to it from the Perl script.

Is there any other ways?

Enjoy,
Peter.

-- 
http://www.interarchy.com/  ftp://ftp.interarchy.com/interarchy.hqx