(mkalias is an executable to create mac aliases)
(The script takes a directory name finds that same name on another drive and creates a mac alias to it inside the named directory and adds a _ to the beginning and .Link to the end.)
The problem I'm having is that the filenames created by mkalias are whacky.
Like this:
_XXX_004_010_Laptop#C93202.Link
It should read:
XXX_004_010_Laptop_Over_O_First_Look.Link
So rather than try to figure that out I think I'd rather truncate the file name at the first 11 characters so it creates:
_XXX_004_010.Link
Is there something I can add so that only the first 11 characters are used?
Please post what Operating System and version you have and what Shell you prefer.
When posting script samples with unexplained variable names, please post the values of those variables. In this case $searchdir , $dir and $suffix.
If you are using a non-industry-standard term like "mac alias", please explain briefly what the term means.
# Diagnostic version of the code
echo "The value of searchdir is: ${searchdir}"
echo "The value of dir is: ${dir}"
echo "The value suffix is: ${suffix}"
find "${searchdir}" -maxdepth 2 -type d -name "${dir}" -print | while read dirname
do
echo "Generated command is: mkalias ${dirname} ./${dir}/_${dir}${suffix}"
done
It's a c shell but I think bash would be better.
Mac alias is the alias files created by the OSX's finder. OsxUtils' mkalias is how I create the aliases through a command line. sveinbjorn.org/osxutils_docs
Here's the script:
#!/bin/csh -f
if ($#argv == 0) then
echo "Renders Alias Maker"
echo " Usage: ram <filename>"
echo "Renders Alias Maker"
exit
endif
### Set input directory from command line:
set dir = $1:r
### Set search directory:
set searchdir = /Volumes/SHOWS/SAV/01_Shots/
set suffix = .Link
### Execute script:
### Original working code:
### find $searchdir -maxdepth 2 -type d -name $dir -exec mkalias {} ./$dir/_$dir$suffix \;
### NEW CODE:
find $searchdir -maxdepth 2 -type d -name $dir -exec mkalias {} ./$dir/_$dir$suffix \;
#!/bin/sh
scriptname=`basename $0`
if [ $# -lt 2 ]; then
echo "Usage: $scriptname srcPath destPath"
exit
fi
srcPath=$1
destPath=$2
if [ ! -e "${srcPath}" ]; then
echo "$scriptname: '${srcPath}': No such file or directory"
exit
fi
# remove possible trailing slash from $srcPath
srcPath="${srcPath%/}"
# set $srcType to "file" or "folder" as appropriate
if [ -d "${srcPath}" ]; then
if [ "${srcPath##*.}" == "app" ]; then
srcType="file"
else
srcType="folder"
fi
else
srcType="file"
fi
if [ ! -d "${destPath}" ]; then
echo "$scriptname: '${destPath}': No such directory"
exit
fi
case "${srcPath}" in
/*) fullSrcPath="${srcPath}" ;;
~*) fullSrcPath="${srcPath}" ;;
*) fullSrcPath=`pwd`/"${srcPath}" ;;
esac
case "${destPath}" in
/*) fullDestPath="${destPath}" ;;
~*) fullDestPath="${destPath}" ;;
*) fullDestPath=`pwd`/"${destPath}" ;;
esac
/usr/bin/osascript > /dev/null <<EOT
tell application "Finder"
set macSrcPath to POSIX file "$fullSrcPath" as text
set macDestPath to POSIX file "$fullDestPath" as text
make new alias file to $srcType macSrcPath at folder macDestPath
end tell
EOT