Jump to content

Make dir and copy file to dir before going ahead


Recommended Posts

Guys, I'm building a workflow which uses pngquant to compress my png's. It works:

/Applications/ImageAlpha.app/Contents/Resources/pngquant {query}
killall Terminal

But I need to copy the selected file to a new folder before compressing it. Kinda backup. How can I do it? thanks!

Link to comment

Guys, I'm building a workflow which uses pngquant to compress my png's. It works:

/Applications/ImageAlpha.app/Contents/Resources/pngquant {query}
killall Terminal

But I need to copy the selected file to a new folder before compressing it. Kinda backup. How can I do it? thanks!

 

Make a folder called PNGTemp in your Documents folder. Create a workflow, add a File Filter, set the File Type to png, set your keyword, then add a Run Script item, leave the language to bash, untick the option to escape spaces, and set the script to do..

full="{query}"
fname=$(basename "$full")
cp "$full" ~/Documents/PNGTemp
/Applications/ImageAlpha.app/Contents/Resources/pngquant "~/Documents/PNGTemp/$fname"

I didn't test it all but I think that should work. It grabs the full path of the file you selected and saves that in a var called full, grabs only the file name and saves that in a var called fname, copies the selected file to ~/Documents/PNGTemp and then compresses the copy of the file, leaving the original in place.

Link to comment

Yes, I understood, but I'm thinking about something like this:

 

images_folder/image.png (compressed)

images_folder/PNGTemp/image.png (original)

 

I want to create a folder in the folder where's is being called from.

 

Edit

 

Already got it!

full="{query}"
fname=$(basename "$full")
dir=$(dirname "$full")
mkdir "$dir"/png-original
cp "$full" "$dir"/png-original

Edited by luco
Link to comment

Yes, I understood, but I'm thinking about something like this:

 

images_folder/image.png (compressed)

images_folder/PNGTemp/image.png (original)

 

I want to create a folder in the folder where's is being called from.

 

Edit

 

Already got it!

full="{query}"
fname=$(basename "$full")
dir=$(dirname "$full")
mkdir "$dir"/png-original
cp "$full" "$dir"/png-original

Awesome, glad you got it figured 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...