Save your files with a simple tag prefix, run this script, and your files are in their proper places.
This script is pre-alpha. Use at your own risk.
Your Desktop folder is so full, you forgot what your Desktop picture looks like. Your Downloads folder is a messy pile of thousands -
You roll up your sleeves and slog through the mess, and after two grueling hours you've finally moved every single file to its rightful place. If only you had a quick, simple way to stop that from ever happening again...
Python Simple TAG Sorter (pSTAGS) to the rescue! Save your files with a simple tag prefix, run the pSTAGS script, and your files are in their proper places.
**/Users/wren/Downloads/pic-cool->**dog-on-a-skateboard-wearing-sunglasses.jpg
**/Users/wren/Pictures/cool/**dog-on-a-skateboard-wearing-sunglasses.jpg
(generated with DocToc)
- What do I need to run it?
- How do I use it?
- Troubleshooting
- What's next for pSTAGS?
- License and Warranty
I've only tested this with Python 2.7.3. If you have an earlier version of Python it might work, and if it doesn't you can upgrade.
You need to know how to run Python scripts from the command line (Windows, Mac OS X), and also know how to make a simple JSON-formatted file for configuration.
As of Nov. 1st, 2012, you'll also need a Mac OS X or Unix-based environment to run it, I haven't tested it with anything else.
pSTAGS needs to know where to sniff for tagged files with a JSON configuration file. Make a new text file called tag-sniff.json
that's in the same directory as the pstags.py
script. Be sure that all of the directories exist on your file system. (If they don't, pSTAGS will warn you!) You can also view this example at tag-sniff.json.default
in the Git repo.
For example: tag-sniff.json
{
"directories": [
"/Users/wren/Downloads/",
"/Users/wren/Desktop/",
"/Users/wren/Documents/unsorted/"
]
}
Declare your list of tags in another JSON config file called tag-maps.json
. You can view this example at tag-maps.json.default
in the Git repo. The JSON key is the tag, and the JSON value is the destination directory:
{
"errands": "/User/wren/Documents/errands/",
"pic-cool": "/Users/wren/Pictures/cool/",
"work": "/Users/wren/Documents/work/",
"mus-theory": "/Users/wren/Music/theory/"
}
When you save a file in one of your pSTAGS sniffed directories, save the filenames with this structure (no spaces):
tagname
->
(separator)file-name.txt
For example:
pic-cool->dog-on-a-skateboard-wearing-sunglasses.jpg
work->BossChristmasFlyer3MonthsTooEarly.doc
Before running the pSTAGS script, your files will be sitting in your sniffed directories, looking woefully out of place.
FILES BEFORE pSTAGS...
/Users/wren/Downloads/pic-cool->dog-on-a-skateboard-wearing-sunglasses.jpg
/Users/wren/Documents/work/unsorted/work->BossChristmasFlyer3MonthsTooEarly.doc
Open up the command line. Navigate to the pstags directory and run python pstags.py
.
Your files are now in the right places, with those clunky tags removed!
FILES AFTER pSTAGS!
/Users/wren/Documents/work/BossChristmasFlyer3MonthsTooEarly.doc
/Users/wren/Pictures/cool/dog-on-a-skateboard-wearing-sunglasses.jpg
--verbose
Verbose output
TODO: Make the script use the argparse
python module to make it a proper command line script with more options.
Pretty much. This is a simple script I put together, and it hasn't been exhaustively tested in different environments. It works for the file sorting tasks I've given it, and has some exception handling.
Tested with the following setup:
- Python 2.7.3
- OS X
This may work on other OSes and previous versions of Python, but they have not been tested. Proceed at your own risk.
Create the tag-sniff.json
and tag-maps.json
files in the same directory as your pstags.py
script. You can use the sample files tag-sniff.json.default
and tag-maps.json.default
as guides.
When the script loads it scans all of the directories given to it and makes sure they all exist before proceeding. You'll have to manually update the tag-maps.json
file if your directories change.
The script will bring up an input prompt confirming if you want to overwrite the file before moving it to its new destination.
Later on I may add a unit testing suite. I'll also make the script use the argparse python module so it has a few more command line options.
Some other ideas:
Logging: Writing output to a log file.
Cron: Enabling support for scheduling with a crontab. Need to consider possibilities of file overwriting if so, since that uses a prompt. Could add a .bak suffix to the original file without overwriting.
Cheat Sheet: A method to generate a cheat sheet for all of your defined tags inside a Markdown or HTML document. A quick reference like this could be very helpful if you have many tags.
This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.
Attribute work to name: Wren Reynolds
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.