#!/usr/bin/perl # make-contents-note-text-file.pl # Version 1.0 # # by Apollia of Astroblahhh.Com. http://astroblahhh.com/ # # # Completed Apr. 1, 2014. # # Released Apr. 1, 2014. # # # Available here: # # http://astroblahhh.com/software/perl/make-contents-note-text-file-v1_0.txt # # # Works in Lucid Puppy Linux 5.2.8, but probably could be modified # to work even in Windows. # # The part that opens an RXVT window is the part most likely to be # incompatible with operating systems that aren't Puppy. # # And then there's the part that uses the Rox-Filer file manager # to open the folder containing the newly-created contents note file. # # # This script just makes a text file named (and containing) # something like this: # # ~Contents - My entire MIDI collection up to 2014 # # Where "My entire MIDI collection up to 2014" is whatever text you want. # # I like to put these files at the root level of various small # TrueCrypt volumes to make it clearer at a glance what they contain. # # # ----- # # # Except for parts not by Apollia: # # Copyright (C) 2014 Apollia # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see http://www.gnu.org/licenses/ . # # # Contact info: http://astroblahhh.com/contact-apollia.shtml ################################################################ # # Some stuff you should leave alone # # This gets the script's location. use Cwd 'abs_path'; use File::Basename qw( dirname ); $this_script_path=abs_path($0); $this_script_parentdirs=dirname( $this_script_path ); print "Running $this_script_path...\n\n\n"; $escaped_script_path=$this_script_path; $escaped_script_path=~s/ /\\ /g; # Makes it possible to use the mkpath function: use File::Path; ################ # # Constants for readability # use constant false => 0; use constant true => 1; # # End of Constants for readability # ################ # End of some stuff you should leave alone # ################################################################ ####################################################################### # # Some stuff you can change # # $full_path_to_folder_in_which_to_create_contents_note_file = $this_script_parentdirs; $MAX_CONTENTS_NOTE_TEXT_LENGTH=240; $file_manager_shell_command_to_use="rox"; $should_open_container_of_contents_note_file_when_script_is_finished = false; # true|false # # If true, the script will open $full_path_to_folder_in_which_to_create_contents_note_file # when finished. # End of stuff you can change. # # # Below this point, nothing else in this script needs to be changed. # # ####################################################################### ################ # # If the user must be asked for input (a prefix or suffix for # the folder name), then, here, we open an RXVT window and # re-run the script. $first_argv_arg=$ARGV[0]; if ( $first_argv_arg != 1 ) # If the RXVT window hasn't been opened yet, # then, the first parameter won't be 1. { exec ("rxvt -rv +sb -sl 999 -e perl $escaped_script_path 1"); # The exec command kills this script and runs the above shell command, # which re-runs this script in an RXVT window with one parameter - # just a 1 - to make this script get past this point during the re-run. } # # End of section where we open an RXVT window. # ################ $full_path_to_folder_in_which_to_create_contents_note_file = AddSlashIfNeeded($full_path_to_folder_in_which_to_create_contents_note_file); Create_Dest_Path_If_Necessary("full_path_to_folder_in_which_to_create_contents_note_file"); sub Create_Dest_Path_If_Necessary { $var=$_[0]; if (!-e $$var) { print "Path doesn't exist yet - $$var \nNow attempting to create path\n\n $$var"; $succeeded = mkpath $$var; if ($succeeded) { print "\n\nPath created!"; } } } CheckForDestPathErrors("full_path_to_folder_in_which_to_create_contents_note_file"); sub CheckForDestPathErrors { $var=$_[0]; if (!-d $$var) { print "\n\nError: "; print $$var; print " is not a directory!\n"; print "Sorry, the path provided in the $var variable doesn't lead to a directory. Please put a different path in $var, or make $$var into a directory, and run this script again."; End_Script_and_Wait_for_Return(); } } sub AddSlashIfNeeded { $this_string=$_[0]; $lastchar = substr($this_string,length($this_string)-1,1); if ($lastchar ne "/") { $this_string .= "/"; } return $this_string; } print "Please type a contents note for the contents note file which is about to be created.\n\n> "; $contents_note_text = ; chomp $contents_note_text; $contents_note_text=~s/[^A-Za-z0-9., _-]/-/g; # Gets rid of bad characters, replacing them with a dash. $contents_note_text=substr($contents_note_text, 0, $MAX_CONTENTS_NOTE_TEXT_LENGTH); print "\n\nDisk volume name: $contents_note_text \n\n\n"; $final_contents_note_text="~Contents - $contents_note_text"; $final_contents_note_file_path=$full_path_to_folder_in_which_to_create_contents_note_file . $final_contents_note_text; sub Create_Text_File_With_Contents_The_Same_As_File_Name { $path=$_[0]; $filename=$_[1]; if (!-e $$path) { print "Contents note file doesn't exist yet - $$path \n\nNow attempting to create contents note file\n\n $$path"; open (contents_note_FILE, ">$$path"); print contents_note_FILE "$filename"; close (contents_note_FILE); if (-e $$path) { print "\n\n\nContents note file created!\n\n"; } } else { print "Contents note file already exists! - $$path \n\nNot remaking.\n\n"; } } Create_Text_File_With_Contents_The_Same_As_File_Name("final_contents_note_file_path", $final_contents_note_text); $final_contents_note_file_path_to_display=$final_contents_note_file_path; if (-e $final_contents_note_file_path) { #chmod 0400, $final_contents_note_file_path; # Owner:Read permissions only. if ($should_open_container_of_contents_note_file_when_script_is_finished) { @system_args=($file_manager_shell_command_to_use, $full_path_to_folder_in_which_to_create_contents_note_file); print "\n\n\nOpening folder containing contents note file, $full_path_to_folder_in_which_to_create_contents_note_file...\n # @system_args\n\n"; system (@system_args); } } else # Couldn't find the folder at the path where it's now supposed to be. { print "The end of the script was reached, but no contents note file was found where it was supposed to be!\n\nTried to create $final_contents_note_file_path but failed."; } print "\n\nScript finished!\n"; print "\nYou can press Return (or Enter) to close this window.\n"; $wait_for_return = ;