#!/usr/bin/perl
# simple-folder-opener-v1_1.pl
# by Apollia of Astroblahhh.Com. http://astroblahhh.com/
#
# v1.1 completed March 29, 2013.
#
# Original version completed on an unknown date.
#
# Comments completed on 5/10/2011.
#
# Public domain.
#
#########################################################################
#
#
# I wrote this script after I discovered that it's not always such a great idea
# to try to use Linux symlinks in the same manner as Windows shortcuts.
#
# Clicking symlinks to folders in the Rox-Filer file manager makes Rox-Filer
# lose track of the actual folder path you're at. (In Rox-Filer, you can
# display the path of the folder you're in, or which Rox-Filer thinks you're
# in, by pressing / ).
#
# Symlinks fool Rox-Filer into thinking you're in a subdirectory of whatever
# folder the symlink was located in, and make it so the Up button goes back
# to the folder containing the symlink, rather than taking you to the real
# parent directory of the folder your symlink brought you to.
#
# In the Lucid Puppy 5.2 variety of Puppy Linux, I could find no simple,
# obvious, built-in way to make a folder shortcut that would behave the way
# a folder shortcut behaves in Windows.
#
# But, after I figured out that it's possible to make Perl scripts that you can
# run just by double-clicking on them, a Perl script seemed like a decent
# solution to this problem, especially because Perl is pre-installed in
# Lucid Puppy 5.2.
#
#
# There's a version of this script which is less cluttered with instructions:
#
# http://astroblahhh.com/software/perl/simple-folder-opener--fewer-comments-v1_1.txt
#
#
# This script won't work in Windows, just Linux. I've only tested it in
# Lucid Puppy 5.2 with the Rox-Filer file manager and the Thunar file manager,
# but it might work with other forms of Linux and other file managers.
#
# It can work with file managers besides Rox-Filer as long as you can
# issue shell commands to that file manager from a terminal.
#
# http://www.murga-linux.com/puppy/viewtopic.php?p=479987
# (Topic: Lucid Puppy 5.2 Official Release JAN 5 2011)
#
# http://en.wikipedia.org/wiki/ROX-Filer#ROX_Filer
# http://en.wikipedia.org/wiki/Thunar
#
#########################################################################
#
#
# Instructions
#
#
# First, if this script is named "simple-folder-opener.txt", rename it
# to something else, like "simple-folder-opener.pl", or the name of the
# folder you wish to make the script open. For example, if you plan on
# making this script open a folder named Links, you could title the
# script "Links", with no filename extension such as .txt or .pl on the
# end.
#
# (In Rox-Filer, you can rename files by right-clicking on them, going
# to the "File '[name of the file you right-clicked on]'" menu, and
# choosing Rename. Be careful to edit only the file name and not the
# file path, because, annoyingly, the Rename function of Rox can do more
# than just rename files - it can actually move files around if you change
# the file path.)
#
#
#
# Next, open the script in a text editor. (In Lucid Puppy 5.2, by default,
# there is an "edit" icon on the desktop which will open a text editor
# named Geany.)
#
# Scroll down past all these instructions to where the script begins, and set
# the $Folder_To_Open variable equal to the path of the folder you want
# to open. (Further instructions are near the $Folder_To_Open variable below).
#
# If you're using the Rox-Filer file manager (the default file manager
# in Lucid Puppy 5.2), you won't have to change the
# $File_Manager_Shell_Command variable.
#
# But if (for example) you're using the Thunar file manager instead of
# Rox-Filer, you'll have to set $File_Manager_Shell_Command equal to
# "thunar" rather than "rox".
#
#
# You will most likely have to give this script Exec permissions to make
# it possible to run this script just by double-clicking on it.
#
# In Lucid Puppy 5.2, if this script file currently has a title ending in
# .txt (like simple-folder-opener.txt), and you have the file on a drive in
# NTFS format (like most hard drives which have Windows installed on them),
# you might be able to make the script executable simply by renaming the
# file to something that doesn't end in .txt, like simple-folder-opener.pl,
# or even a file name without any filename extension such as .txt or .pl on
# the end.
#
# That works for files on my NTFS-format hard drive, but not with files
# located in Puppy's RAM disk.
#
#
# Another, more reliable way to grant Exec permissions to this script is:
#
# In Rox-Filer, right-click this simple-folder-opener.pl script,
# go to the "File 'simple-folder-opener.pl'" menu, and choose Properties.
# Then, put a check in the checkbox across from Owner and under Exec, and
# click Close.
#
#
# Now, to run this script, you should be able to just double-click on it.
# If it worked, the folder in $Folder_To_Open should immediately open.
#
# If it didn't work, perhaps you put in a typo and it's causing
# an error. If you would like to see what error is possibly happening,
# you can run this script from a terminal window.
#
# In Rox-Filer, you can do that by going to the folder this script is
# in and pressing `. (The backtick key. In case you rarely or never
# use that and don't know where it is - it might be at the upper left
# of your keyboard below the Esc key.) That will open an RXVT terminal
# window. Then, type:
#
# perl simple-folder-opener.pl
#
# (or whatever the name of your script is)
#
#
# Another possible reason this script might not work: this script is
# unable to open any folder on a disk that you have not yet mounted.
#
# In Lucid Puppy 5.2, disks are automatically mounted when you open
# your disks' desktop icons.
#
#
# Yet another reason this script might not work is:
#
# If you're using some other kind of Linux other than Lucid Puppy 5.2,
# and Perl on your system is located somewhere other than
# /usr/bin/perl, I'm guessing you might have to change the "shebang"
# line at the top of the file to the correct path of Perl on your system.
#
# http://www.computerhope.com/jargon/s/shebang.htm
#
############################################################################
#
#
# Adding a custom icon to this script in Rox-Filer in Lucid Puppy 5.2
#
#
# Note: As of 5/10/2011, I haven't yet released the Perl script I use at
# startup to restore various updated settings - the script which
# rescues me from having to save an entire new session to my Puppy
# DVD just to save some minor settings updates.
#
# So, until I release that startup script, the below instructions
# won't be quite as useful, unless you write your own Perl
# script to copy your saved copy of Rox-Filer's "globicons" file
# into Puppy's RAM disk.
#
#
# I have a folder where I store a bunch of these simple-folder-opener scripts.
# To make it more obvious at a glance that these scripts are shortcuts to a
# folder, I gave the scripts this icon:
#
# http://www.iconarchive.com/show/shining-z-icons-by-zakar/Folder-Downloads-SZ-icon.html
#
# Of course, you can use any icon you want instead of that one. There are
# _tons_ of nice icons on http://iconarchive.com/ - and all of them are
# available in formats you can use in Rox-Filer.
#
#
# In Rox-Filer, you can use icons in either ICO format or PNG format, and maybe
# other formats that I haven't tested. (I prefer icons in 48x48 PNG format
# since they often have a much smaller file size than ICO files).
#
# Make a folder somewhere to put icons, preferably in a permanent location,
# because if you ever move your icons from the place Rox-Filer thinks they're
# in, you'll have to update Rox-Filer with the new locations.
#
# Also, choose a preferably permanent location to put your simple-folder-opener
# scripts, because if you ever move them to a new location, Rox-Filer won't
# retain their custom icons and you'll have to redo them.
#
# Next, in Rox-Filer, right-click on one of your simple-folder-opener scripts.
# From the "File '[name of your script]'" menu, choose Set Icon. Open your
# folder for icons, then click and drag the icon you want to use onto the
# Set Icon window and click Close.
#
#
# If you have a lot of scripts to set an icon for, go to this path:
#
# /root/.config/rox.sourceforge.net/ROX-Filer/
#
# (An easy way to go to this (or any) path in Rox-Filer:
#
# Press the / key in any Rox-Filer folder window. Then, at the bottom of the
# window, the "Goto:" address bar will pop up, containing the current folder
# path. Paste in the above path to go directly to it.)
#
#
# Once in that folder, open the file "globicons" in a text editor.
#
# If you already set at least one script's icon by right-clicking on the
# script and choosing Set Icon in Rox-Filer, there will be some lines in
# "globicons" which refer to that script whose icon you set. Find those
# lines by by using your text editor's Find function and searching either
# for the name of your script, or the name of your icon file.
#
# Then, copy the three lines that define your script's icon - they start
# with and end with ,
# and will look something like this:
#
#
# /mnt/sda3/Puppy/Icons/Folder-Downloads-SZ.ico
#
#
# Immediately below any line which says , paste the three lines you
# copied. Then, in the text you pasted, change the path specified in the
# to the path of another one of your scripts. Repeat
# as needed for each of your script files, then save the globicons file.
#
# To make your new custom icon(s) be displayed, go to your scripts' folder
# and click the button at the top of the window with two curvy blue arrows,
# the button which says "Rescan directory contents" when you hover the
# mouse over it.
#
#
# If you're running Puppy on a live CD or DVD, you can save your new custom
# icon settings by saving a new session on your Puppy disc.
#
# Alternatively, if you'd rather not save an entire new session just to save
# such a minor settings update, copy the "globicons" file to your hard drive
# or Flash drive or something.
#
# Anytime you reboot Puppy, you can use a Perl script to copy those settings
# from their location on your hard drive or Flash drive, over to
# /root/.config/rox.sourceforge.net/ROX-Filer/ . Then press the "Rescan
# directory contents" button (the one with the curvy blue arrows) in a
# Rox-Filer window to make Rox-Filer start displaying your icons.
#
# At some point in the future, I'll release the Perl script I use
# when I start up Puppy on http://astroblahhh.com/ .
#
#
####################################################################
#
#
# The script begins below.
#
$Folder_To_Open="/mnt/sda3/";
# Example Linux path:
#
# /mnt/sda3/
#
# In Linux, all absolute paths begin with a slash. If the path
# goes to a folder, it's good to also end the path with a slash to show
# that it's a path to a folder. However, this script will still
# work (at least with Rox-Filer and Thunar) even if you forget the
# last slash.
#
#
# In Rox-Filer, you can obtain the path of the folder you're in by,
# if necessary, clicking on the folder window (if it's not already the
# selected window) and pressing the / key. The current path will appear
# at the bottom of the window.
#
# You can highlight and copy the path text by clicking the path text,
# pressing Ctrl-A and pressing Ctrl-C.
#
# Then, open this script in a text editor. Go to the $Folder_To_Open
# variable, highlight the text within quotes after that variable, and
# press Ctrl-V to paste in the path you copied.
#
#
# If you're a Puppy Linux newbie who is mystified about what path your
# disk drives are at, your disk drives can be found in the /mnt/ folder,
# bearing mysterious names like sda2, sda3, sdb1, or sr1. (Fortunately,
# many Puppy Linuxes provide shortcuts to your disk drives on your
# desktop).
#
# On my computer, sda2 is the C partition of my hard drive, sda3 is
# the D partition, sdb1 is my Flash drive, and sr1 is my DVD writer
# drive.
$File_Manager_Shell_Command="rox";
# You can leave this alone if you're using Rox-Filer.
#
# "rox" is the shell command to launch Rox-Filer.
#
# If you're using a file manager other than Rox-Filer (the
# default file manager in Lucid Puppy 5.2), you'll need to set the
# above $File_Manager_Shell_Command variable equal to the shell command
# which launches your other file manager.
#
# I haven't tested a lot of alternative file managers, but, the Thunar
# file manager will definitely work with this script. Set
# $File_Manager_Shell_Command equal to "thunar" if you're using Thunar.
#
#
# Nothing beyond this point needs to be changed.
exec ("$File_Manager_Shell_Command \"$Folder_To_Open\"");
# The below two lines are an alternative way to accomplish exactly the
# same thing as the above exec line - namely, opening $Folder_To_Open with your
# file manager.
#chdir $Folder_To_Open;
#exec ($File_Manager_Shell_Command);