Home > Software design >  Referencing both original and converted file in Automator
Referencing both original and converted file in Automator

Time:10-16

I'm trying to create an Automator app that would work like this:

  1. You would drag any type of image file onto the app.
  2. The app would make a duplicate of the file, convert it to JPEG, scale it down to 500px, remove the " copy" part at the end of the filename.
  3. Upload the original file to a specific folder on my Dropbox account.
  4. When step 3 is done, upload the converted JPEG to another specific folder on my Dropbox account.
  5. Delete the converted JPEG locally when the process is finished.

Steps 1 and 2 are working. I've also found a Automator flow

The part I'm stuck at is how to first upload the original image file with one shell script and then upload the converted file with another shell script. I guess that I have to store a reference for both in some way?

I'm also not quite sure how to specifically delete the JPEG after everything is done.

CodePudding user response:

I think with the Set Value of Variable and Get Value of Variable actions you can achieve what you're trying to do here.

This workflow provides an example of using these. You can set multiple different named variables, and then read and reuse them later. To get this workflow to work properly I had to select Ignore this action's input for the Get step, otherwise it used both the value of example (which was the filename of the file dropped onto the app) and also the output of Ask for confirmation (which was the filename again, so it tried to move the same file to the Trash twice).

When creating a variable you just choose New Variable... from the drop-down menu. You then give it a name, and leave the Value box empty (and it gets set from the Set... action's input).

new variable

Once you have a Variable set up you can also drag it into some places (from the Variable section at the bottom of the window), as I've done here to make the file path show up in the Ask for Confirmation action. You can also remove any unused variables by right-clicking on the variable in the Variable section, and choosing Delete exampleVariable

example workflow

Full steps which I think would complete your full workflow could be:

  1. Set Value of Variable first, to store your 'original filename' in variable original (or something), then the parts of the workflow you already have:
  2. Duplicate file
  3. Convert to to JPEG
  4. Scale
  5. Remove "copy"
  6. Set Value of Variable converted to input
  7. Your already-working upload shell script step
  8. Get Value of Variable to read converted back in (this should have Ignore this action's input ticked)
  9. Move Finder Items to Trash to remove the JPEG file (could be a shell script to delete the file immediately)
  10. Get Value of Variable to read original back in (this should also have Ignore this action's input ticked)
  11. Your upload shell script step again (to upload this time the original file)
  12. Display happy alert message
  • Related