##########################################################################
# THIS IS FREE PERL PROGRAM TO SYNC YOUR FILES ON MAC OS X               #
# IT IS HELPFUL TO SYNC YOUR APPLICATIONS LIKE MAIL, ADDRESS BOOK ETC.   #
# NO iMAC ACCOUNT REQUIRED                                               #
# SYNC COULD BE DONE ON THE LOCAL NETWORK OR VIA INTERNET                #
# PERL SCRIPT WRITTEN BY WEB DESIGN CO. http://www.wd-co.com             #
# LICENSE: GPL                                                           #
# rsync SOFTWARE MUST BE INSTALLED ON YOUR MAC IN ORDER FOR THIS PROGRAM #
# TO WORK. USE FINK TO INSTALL THE LATEST VERSION                        #
# THIS PROGRAM PROVIDED "AS-IS" - USE IT AT YOUR OWN RISK                #
# WHEN SYNCHRONIZING FILES - MAKE SURE PROGRAM IS NOT USING FILES AS     #
# THEY MAY BE LOCKED                                                     #
# i.e. IF YOU COPYING MAIL FILES - kill -9 mail.app ON BOTH MACHINES     #
# NO RSYNC SERVER SETUP REQUIRED FOR THIS PROGRAM TO WORK                #
# RUN THIS PROGRAM FROM THE TERMINAL. OTHER USE WAS NOT TESTED           #
##########################################################################
&getfiles;
print "Select the files you want to update:\n";
foreach $f (sort num keys (%fled)) {
$fv = $fled{$f}; $tnokz++;
$cmb = "$cmb$f\. $fv\n";
}

	print $cmb;
print "\tSelection: ";
$file = <STDIN>; chomp $file;
&iter;

## CHANGE HOSTS ACCORDING TO YOUR LOCAL NETWORK SETTINGS
## TO KNOW THE NAME OF THE COMPUTER ON THE NETWORK JUST
## RUN THE /bin/hostname FROM THE TERMINAL ON EACH COMPUTER
## AND ENTER THE VALUES BELOW
%hsts = ('YourWorkstationExampleMac.local','1',
'YourPowerBookMac.local','1');

## THIS IS FILE WITH YOUR REMOTE MACHINE IP ADDRESS
## WE USE MAIL RULE TO EXTRACT THIS ADDRESS FROM 
## SERVER REPORT EMAIL SEE THE PROGRAM AT THE BOTTOM
## OF THE FILE
## IP VARIABLE STORED IN THE FILE: $ipCr = 'xxx.xxx.xx.xxx.';
if(-f "CurrIP.cgi") {
undef $@; 
eval {require "CurrIP.cgi"};
	unless($@) {require "CurrIP.cgi";
$hsts{$ipCr} = 1;
	} ## END GOOD EVAL
} ## END IF IP FILE PRESENT

$hostname = `/bin/hostname`;	chomp $hostname;
print "\n\t\trsync will be performed from $hostname computer\n";
if($hsts{$hostname}) {delete $hsts{$hostname};
print "We could upload/download files to the following computers:\n";
	foreach $hst (sort keys(%hsts)) {$hstn++;
print "$hstn\. $hst\n";
$realcmp{$hstn} = $hst;
	}
print "Computer selection: ";
$comp = <STDIN>; chomp $comp;
	if($realcmp{$comp}) {$host = $realcmp{$comp};}
	else {print "Wrond Computer selection -\> exiting\n"; exit(0);}
} ## END IF HOST PRESENT IN A TABLE
else {print "\"$hostname\" was not found in a host table\n"; exit;}
	$host =~ s#\.local##;
print "\n\tMake a Test run (y/n)? ";
$tst = <STDIN>; chomp $tst;
if(length($tst) > 1) {$tst = substr($tst,0,1);}
if($tst eq 'n') {$testrun='A';}
elsif ($tst eq 'y') {$testrun = ' --dry-run';}
	unless($testrun) {print "Test run was not specified - exiting\n"; exit(0);}
$testrun =~ s/A//;

print "\nPlease verify your selection:\n\tComputer exchange files with: $host\nFiles:\n";

foreach $file (@allfiles) {
unless($flez{$file}) {next;}
$cmbf{$file} = $flez{$file};
print "\t$file -> $flez{$file}\n"; $nofzd++;
} ## FOREACH FILE END
	if($nofzd < 1) {print "No files selected so exiting\n"; exit(0);}

	undef %fled;	undef %flez;	undef %realcmp;

foreach $file (sort keys(%cmbf)) {$excl='';
$actf = $cmbf{$file};

print "Upload/Download (u/d): ";
$upldd = <STDIN>; chomp $upldd; $upldd =~ tr/A-Z/a-z/;

@lvf = split(/\//,$actf); pop(@lvf);
$ffile = join "/", @lvf;
unless($ffile) {$ffile = '/';}

	if($upldd eq 'u') {$ffile =~ s# #\\\\\\ #g; $actf =~ s# #\\\ #g;
$ffile = "$host\:$ffile";
	} ## END UPLOAD
	elsif($upldd eq 'd') {$ffile =~ s# #\\\\\\ #g; $actf =~ s# #\\\\\\ #g;
$actf = "$host\:$actf";
	} ## END DOWNLOAD
	else {print "\nNothing requested, skipping\n"; next;}

print "\t$actf $ffile\n";
my $aa = system("time rsync -a -c -vvv$testrun$excl $actf  $ffile --update");
print "$aa\n";
} ## FOREACH FILE END

exit(0);
	sub num {$a <=> $b;}
sub iter {
for (1..$tnokz) {
$expl = $fled{$file};
if($expl eq 'Custom File or Directory') {
print "Enter full path to the file or directory\n       or drug and drop file from finder: ";
$file = <STDIN>; chomp $file; $file =~ s/\s+$//; $file =~ s/^\s+//; $flez{$expl} = $file;
} ## END CUSTOM FILE
unless($expl eq 'Next Step' || $expl eq '') {&nextfile;	$file = <STDIN>;	chomp $file;}
}
} ## END SUB ITER

sub nextfile { #############
push @allfiles, $expl;	print "Selected: $expl ($file)\nAdditional Selections:\n";	$cmb =~ s#$file\. $expl\n##;
print $cmb;	print "\tSelection: ";	delete $fled{$file};
} ## END SUB NEXT FILE #####

sub getfiles { #################
## YOUR GOTTA FIGURE THIS ONE OUT ON YOUR OWN AS TWO HASHES BELOW WORK TOGETHER
## VALUE IN SECOND HASH IS THE KEY FOR THE FIRST ONE
## ADD OR REMOVE THE KEYS AND VALUES PER YOUR OWN REQUIREMENTS
## CHANGE user TO THE ACTUAL USER USED ON BOTH MACHINES USER MUST BE VALID
## AND IDENTICAL - OTHERWISE PROGRAM WILL NOT WORK OR YOU MAY 
## WANT TO INCORPORATE ADDITIONAL PROCEDURE TO MAKE IT WORK

## FILES HASH
%flez = (
'Fire users','/private/var/user/Library/Preferences/Fire.plist',
'Fire program','/Applications/Fire.app',
'Fire Settings and Messages','/private/var/user/Library/Application Support/Fire',
'CuteFTP Application','/Applications/CuteFTP Mac.app',
'CuteFTP Addresses','/private/var/user/Library/Preferences/CuteFTP AddressBook.plist',
'CuteFTP Settings','/private/var/user/Library/Preferences/com.globalscape.CuteFTP2.plist',
'iTunes Music','/private/var/user/Music/iTunes/iTunes Music',
'Mail Accounts and Mailboxes','/private/var/user/Library/Mail',
'Mail Program','/Applications/Mail.app',
'Mail Prefereces','/private/var/user/Library/Preferences/com.apple.mail.plist',
'Safary Bookmarks','/private/var/user/Library/Safari/Bookmarks.plist',
'Address Book Data','/private/var/user/Library/Application Support/AddressBook',
'Custom File or Directory','cust'
);

## FILE NAME CONVERSION HASH
%fled = (
'1','Fire users',
'2','Fire program',
'3','Fire Settings and Messages',
'4','CuteFTP Application',
'5','CuteFTP Addresses',
'6','CuteFTP Settings',
'7','iTunes Music',
'8','Mail Accounts and Mailboxes',
'9','Mail Program',
'10','Mail Prefereces',
'11','Safary Bookmarks',
'12','Address Book Data',
'14','Custom File or Directory',
'15','Next Step'
);

} ## END SUB GET FILES #########

## APPLESCRIPT TO EXTRACT IP WHEN MAIL RULE MATCHES
## ADOPTED FROM APPLE HELP APPLESCRIPT EXAMPLE
## IP STORED IN A SUBJECT OF THE EMAIL MESSAGE AND
## EXTRACTED BY THE APPLESCRIPT
## USE APPLESCRIPT LINES AND REMOVE THE $scrpt VARIABLE
$scrpt = '
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with eachMessage in theMessages
				set theSubject to subject of eachMessage
				try
					if theSubject is not equal to "" then
						do shell script "/Path_to_the_Perl_script/WritingIP.cgi " & theSubject
					end if
					-- set theText to theSubject
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from
';

## PERL SCRIPT TO WRITE THE IP ADDRESS CALLED FROM APPLESCRIPT
## UNCOMMENT LINES BELOW AND ADD SHEBANG

## WritingIP.cgi Perl script

## SHEBANG HERE - SNIPPED
#$d = $ARGV[0]; $d =~ s/\\//g;
#
#if($d =~ m/\d/) {
#	open(TXT,">/PathToFile/CurrIP.cgi");
#	print TXT "\$ipCr = '$d'\;"; close(TXT);
#} ## END IF MATCHES DIGIT
Promote Your Web Site on Thousands of Pages