Jump to content

Workflow to change image resolution


Recommended Posts

Hi all, I tried building an Automator or Shortcut or Alfred workflow and failed each time 😞.

 

My goal:

1. convert images to TIFF

2. change the resolution of the TIF to 300 DPI (either with sips or imageprep [?])

3. move source file in a subfolder called Archive.

 

I'm able to do step 1/2 with this shell script

imageprep -r 300 -f tif

 

But I don’t know how to do the rest… and / or get the selected files in the folder.

I also tried building a workflow with Alfred Automations

 

I think I'm turning in circle in my living room now. Any insight would be appreciated! 😅

Link to comment

On the assumption you're using a Universal Action to select the files in the first place it's actually reasonably easy to do what you wish. It's probably easiest if I point you to a workflow on the Alfred Gallery which should help with your programming. (Full disclosure: I wrote the workflow.)

 

Take a look at my Move to new folder workflow. You should be able fairly easily to adapt pieces of that. If your Archive folder is in the same location every time you use your workflow you can adapt the workflow so as not to prompt for the folder location each time, of course.

 

By all means post again if you still have problems.

 

Stephen

Link to comment
34 minutes ago, JolinM said:

I still don't know how to run my imagepre shell script with success in Alfred

You should be able to do that by linking your keyword to an Alfred Run Script action and then proceed from there. See here for Alfred help on reading environment variables (which will help you feeding the files into your script).

 

Stephen

Edited by Stephen_C
Link to comment
  • 2 months later...

Well done! Now see if you can cater for others whose path to the Desktop (and user name) is not the same as yours. By way of a hint, take a look at the workflow configuration in, for example, my Save 'ur note workflow. The workflow configuration can be a great help for users. For example, you could mention in it the need to download and install imageprep and provide a link to the download. Take a look at this Alfred help page about workflow configuration.

 

(I should say that I've not run the workflow—although I downloaded and looked at it—because I have neither tiffs nor imageprep. However, I'm sure you've checked that it works!)

 

Stephen

Link to comment

Almost there! I now have a configuration page + requirement.

Only thing I still can't figure is how to loop my script for each selected file. Should that be done with a Split Arg Utility?

My current selection from the Finder is formatted like this:

"/Users/jolinmasson/Desktop/photo 1.jpg",
"/Users/jolinmasson/Desktop/photo 2.jpg",
"/Users/jolinmasson/Desktop/photo 3.jpg"

 

Link to comment

Sorry to keep directing you to my own workflows but it's easier than trying to describe here the detail of what you need to do. Take a look at Shrink JPEG/PNG Files on the Alfred gallery. The workflow is quite clearly annotated so you'll be able to work out how it deals with more than one selected file.

 

Stephen

Link to comment

Working by examples and reverse engineering existing workflows is really great, help's a lot!

In this case, your workflow seems to be a File Action. As mine start with a Keyword + Finder section, I'm struggling to connect the right thing.

Here's where I'm at.

Really appreciate the help btw!

 

Capture d’écran, le 2024-01-11 à 16.41.50.png

Link to comment

I'm rather short of time just at the moment so I'm sorry if this response is not as helpful as it might be. My quick comments are:

  • I would definitely start with a Universal or File Action for a workflow like this (although you can clearly use a keyword if you really prefer to do so).
  • Generally, you need to review how parameters are passed to a shell script—because you're trying potentially to pass more than one parameter (i.e., file name) but have provided (I think, with the incorrect syntax) for only one. You may also need to check how imageprep deals with multiple parameters (although I can't imagine that would differ from any command line tool).

Apologies for not being more helpful: have to dash off to swim! 😀

 

Stephen

Link to comment

OK, now, rather more helpfully (I hope!)…

 

First take a look at something like this page about using command line variables, so that you get the general idea: How to Use Command Line Arguments in a Bash Script.

 

Next, bear in mind you're not going to know, when using the workflow, whether you have only one, or more than one, file selected. That means you're going to need something like this in your shell script:

for var in "$@"
do
[your relevant imageprep command substituting "$var”, quoted like that, for your variable in the shell command]
done

 

In passing, you've probably not chosen the easiest start to learning workflows—but that's the way we all learn!

 

Stephen

Link to comment

Well done! The only thing I would do (and it's purely a personal preference) is to add, after the shell script, a notification action confirming conversion of the file(s)and the file's/files' location. Note that you can use {var:destinationFolder} in the notification so that it shows the correct destination folder configured by the user.

 

I like that sort of notification because it reassures the user that something has actually happened and reminds the user where what has happened can be found!

 

Stephen

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...