ASKSOL%%C L I P B O A R D small hacks, hints, ramblings and useful and unuseful solutions
These are some automator scripts that I made for my personal use.
They are to be used with the automator context menu, to install them just
unzip and copy to HOME/Library/Workflows/Application/Finder.
I share them here just in case someone else find them useful.
I do not maintain them, but suggestions are welcome.
The key to using shell scripts with Automator is the Run Shell Script action.
This is a script for the Automator context menu that creates a new text
file in the selected folder. (It appends a numeric suffix to the filename if
the default filename New text file.txt already exists)
#!/bin/bash
# AUTOMATOR SCRIPT: Create new text file.
# DESCRIPTION : To be used with "Get selected Finder items" in
# a Finder automator context menu script, simulating the
# "Create new text file" menu item in Microsoft Windows(TM).
# VERSION: 0.1.0
# AUTHOR: (c) 2006 Ask Solem Hoel [asksol@gmail.com]
############################################################################
# The name the text file start with.
TEMPLATE_NAME="New text file"
# The filename suffix.
TEMPLATE_SUFFIX="txt"
# Max number of text files if a text file
# with the name above already exists.
MAX_ITERATE=64
if [ -d "$1" ]
then (
cd "$1"
c=0;
while [ 1 ]
do
template_iterate_name="$TEMPLATE_NAME"
if [ $c -gt 0 ]; then
template_iterate_name="$template_iterate_name ($c)"
fi
template_iterate_name="${template_iterate_name}.$TEMPLATE_SUFFIX"
if [ ! -e "$template_iterate_name" ]; then
touch "$template_iterate_name"
break;
fi
if [ $c -gt $MAX_ITERATE ]; then
break
fi
c=$(expr $c + 1)
c=$(echo $c | perl -pe'/(\d+)/;$_=$1')
done
) fi
Download full workflow here:
New.text.file.workflow.zip
then unzip and move it to HOME/Library/Workflows/Application/Finder/.
Short simple one that uses the unzip unix executable shipped with MacOS X to
unzip all the .zip files in a selected directory (or several if you'd like)
The files are unzipped in either the directory that was selected (if a directory was selected)
or in the parent directory of the selected zipfile (if a file was selected).
#!/bin/bash
# AUTOMATOR SCRIPT: Unzip selection
# DESCRIPTION: Unzips all zipfiles in a selected directory.
# UPDATE: [2006-12-11] Now also unzips single files.
# VERSION: 0.1.2
# AUTHOR: (c) 2006 Ask Solem Hoel [asksol@gmail.com]
##############################################################
for f in "$@"
do
if [ -d "$f" ]; then
(cd "$f"; for z in *.zip; do unzip -o "$z"; done)
fi
if [ -f "$f" ]; then
(cd ${f%/*}; echo "$f" grep -qE "\.zip$" && unzip -o "$f")
fi
done
Download full workflow here:
Unzip.all.zipfiles.in.directory.workflow.zip
then unzip and move it to HOME/Library/Workflows/Application/Finder/.
[UPDATE 2006-12-11]
Now support unzipping of single files and doesn't continue with anything
if the input is not a file or directory.
I've noticed that if you right-click on the background and select a automator
script instead of selecting a file/dir it won't do anything. So this is a workaround
for the above when you already are in the directory.
Just select a file, and this script will unzip all the zipfiles that are in the same
directory as the file you selected.
#!/bin/bash
# AUTOMATOR SCRIPT: Unzip all files in selected file's dir
# DESCRIPTION: Select a file, and this script will unzip all
# zipfiles in the same directory as the selected file.
# VERSION: 0.1.2
# AUTHOR: (c) 2006 Ask Solem Hoel [asksol@gmail.com]
##############################################################
f=$1
if [ -f "$f" ]; then
(cd "${f%/*}"; for z in *.zip; do unzip -o "$z"; done)
fi
Download full workflow here:
Unzip.all.zipfiles.in.directory.of.file.workflow.zip
then unzip and move it to HOME/Library/Workflows/Application/Finder/.
The MP3 scene release groups uses strict naming standards for their mp3 files
so automaticly parsing the artist and albumtitle/songname is no problem. This
script extracts the artist name out of a directory name like Foo-Bar-Retail_CD-2006-FooGrp and
searches for Foo in Discogs, the online electronic music database.
You can change this to the website you want.
#!/bin/bash
# AUTOMATOR SCRIPT: Find artist from MP3 scene file name.
# DESCRIPTION: -"-
# SYNOPSIS: To be used with the Display Webpages action.
# VERSION: 0.0.1
# AUTHOR: (c) 2006 Ask Solem Hoel [asksol@gmail.com]
################################
ARTIST=$(echo "$1" | perl -pe's/^(.*?)\-.*/$1/;s/_/ /g')
URL="http://www.discogs.com/search?type=all&btn=Search&q=${ARTIST##*/}"
echo $URL
You should use this with the Display Webpages action in Workflow.
Download full workflow here:
Find.Artist.workflow.zip
then unzip and move it to HOME/Library/Workflows/Application/Finder/.