Jump to content
Sign in to follow this  
luco

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!

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  
×
×
  • Create New...