Untangle a long macro: Wait for unzipping and open specific file in folder

I have a macro that does the following:

  • On a web page in Firefox, opens the download section for a file, identifies a form of download (zip file) and downloads it.
  • Unpacks the zip file.
  • Opens the unzipped folder, looks for a text file that always starts with the same unique letter and contains metadata.
  • Reads out the metadata, stores it in different variables.
  • Generates a text template from the variables.
  • Opens another website to process the image files from the folder

Until now, this was a long macro, which occasionally worked, but due to many fixed pause periods, had problems when downloading or unpacking could not be processed in time.

Accordingly, I am currently splitting it into partial macros that can be used independently of each other (e.g. if an unpacked folder is already available) and that are executed step by step after a user query.

Here are my (first) three questions:

  • How can I make the macro wait while unzipping a folder (duration: between a second and half a minute) before proceeding automatically? I start with a file e.g. named SPS18236644.zip (same SPS prefix everytime) and end up with a folder named SPS18236644.

  • Currently I open the downloaded file and identify the file containing the metadata (only file that starts with S) in the following way:

Actions (v10.2)

Keyboard Maestro Actions.kmactions (2.7 KB)

  • How can I make this more robust and independent from moving around in Finder using keystrokes (open the file S-Metadata-File.txt in last added folder in Downloads)?

  • How to best save the path of the unzipped folder for later use?

Thanks for giving me some suggestions on how to proceed.

To make the macro 'wait': I'd use a shell script to unzip the files, since the action won't complete and move through the macro until the unzip is complete, something like this (assuming you want to unzip the currently selected zip file in finder into the same path)

To save the output- you could use the output of the shell script to parse the path of the unzipped file/folder, save it to a variable and perform whatever other actions on it you need.

  1. "Make the macro wait while unzipping a folder"

Two ideas...

If the unzipper is set to move the zip file to the Trash after unzipping, you could Pause Until: "At this path": "A file does not exist": %Variable%LocalFile%.

Alternatively, use a third-party application to unzip, and set its preferences so that it quits after unzipping. The macro can then be set to Pause Until this application is "not running". This wouldn't work in the same way if you use the MacOS Archive Utility. Also, this won't be the quickest method.

  1. "How to best save the path"

Up to you. Maybe in a global variable?