Jump to content

Problems with Shell Scripts


Recommended Posts

Hello,

 

Actually I'm trying to generate an alfred workflow which make iso out of selected folders in finder.

 

The File Action is working. But my problem is, how can I execute Shell Commands in the parent folder, so that I can run hdiutil, etc...

 

All experiments went wrong.. Maybe anybody has a tipp for me?

 

thx

 

To do this, you would need to add a Run Script item to the workflow and then change to the directory that you wish to work in. You could find that directory by taking one of the selected files and running `dirname` on it. Then `cd` to that directory. All scripts in Alfred start in the path relative to that workflow.

Link to comment
  • 2 months later...

Thx for your reply. If I run the following script within bash it works / on File Action it don't works:

QUERY="{query}"

if [ -d "$QUERY" ]; then
	PARENTDIR=`dirname $QUERY`
	DIR=`basename $QUERY`
	FILEEXTENSION=".iso"
	cd $PARENTDIR
	mkisofs -o $DIR$FILEEXTENSION $DIR
fi

Are there any special things to set?

 

Have you checked your escaping options to ensure that they are set correctly? It could be escaping spaces in the file path and then when you have it set to save "{query}" its maintaining the actual \ to escape as part of the path which, could cause an issue. Or, if it's not escaping the spaces, putting the command in back ticks... The file path may need to be in quotes.

 

Try adding an output->large type, or an output->notification and echo the values of a few of your variables and ensure that they contain the expected values.

Link to comment

Thank u for your reply :-)

 

  • I have enabled all escaping options except "Backslashes"
  • The following script now works.
    • But if you look at the code, I've tried to create the complete output path in variables. But this does not work. For now it is ok, but I want to  extend the workflow and for this it would be nice if this also works.

Do you have an idea?

FOLDER=$(basename {query})
FOLDERMIN=${FOLDER//[[:blank:]]/}

FINALFOLDER="~/Desktop/$FOLDER.iso"
FINALFOLDERMIN="${FINALFOLDER//[[:blank:]]/}"
echo $FINALFOLDERMIN


#hdiutil makehybrid -iso -joliet -o $FINALFOLDERMIN {query}
hdiutil makehybrid -iso -joliet -o ~/Desktop/$FOLDERMIN.iso {query}

if [ -f ~/Desktop/$FOLDERMIN.iso ]
then
    echo "ISO file '$FOLDER'.iso is available on your desktop"
else
	echo "File is not created! Anything went wrong."
fi
Link to comment

EDIT: The problem were the double quotes.

 

Now following works with a single folder:

FOLDER=$(basename {query})
FOLDERMIN=${FOLDER//[[:blank:]]/}
FINALFOLDER=~/Desktop/$FOLDERMIN.iso


hdiutil makehybrid -iso -joliet -o $FINALFOLDER {query}

if [ -f $FINALFOLDER ]
then
    echo "ISO file $FOLDER.iso is available on your desktop"
else
	echo "File is not created! Anything went wrong."
fi

My next step is to extend code, that it also can handle multiple folders (each folder to iso file)

Link to comment

Finally creation of multiple iso files works:

OIFS=$IFS
IFS="	"

foldersArray=({query})

for ((i=0; i<${#foldersArray[@]}; ++i))
do
	ir=$(expr $i + 1)
	folder=$(basename ${foldersArray[$i]})
	folderMin=${folder//[[:blank:]]/}
	parentFolder=$(dirname ${foldersArray[$i]})
	folderFinal=$parentFolder/$folderMin.iso

	hdiutil makehybrid -hfs -iso -joliet -o $folderFinal ${foldersArray[$i]} > /dev/null

	if [ -f $folderFinal ]
	then
		echo "$ir: $folderMin.iso created"
	else
		echo "$ir: Creation of $folderMin.iso went wrong!"
	fi
done

IFS=$OIFS
Link to comment

 

Finally creation of multiple iso files works:

OIFS=$IFS
IFS="	"

foldersArray=({query})

for ((i=0; i<${#foldersArray[@]}; ++i))
do
	ir=$(expr $i + 1)
	folder=$(basename ${foldersArray[$i]})
	folderMin=${folder//[[:blank:]]/}
	parentFolder=$(dirname ${foldersArray[$i]})
	folderFinal=$parentFolder/$folderMin.iso

	hdiutil makehybrid -hfs -iso -joliet -o $folderFinal ${foldersArray[$i]} > /dev/null

	if [ -f $folderFinal ]
	then
		echo "$ir: $folderMin.iso created"
	else
		echo "$ir: Creation of $folderMin.iso went wrong!"
	fi
done

IFS=$OIFS

 

Sorry it took me a while to get back to ya. You were working on this... a little before I got out of bed :) 2:40am is a little early for me ha.

 

Glad you got it worked out

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...