Jump to content

Compress universal action


akrabat

Recommended Posts

I'd like to submit my Compress universal action to the Alfred Gallery if it's useful enough to warrant it.

 

I am the author and the link to it's Alfred Forum thread is: https://www.alfredforum.com/topic/20355-compress-universal-action/

 

It's published on GitHub at https://github.com/akrabat/alfred-compress/ and has no dependencies.

 

Given a selected file or folder in Finder and triggering Alfred's universal actions, it provides "Compress" and "Zip" options that create a zip file of the selection that is placed in the same directory as the selection.

screenshot.thumb.png.0267e0418c5a041ab587fd6c3f7e0d1b.png


 

 

Link to comment
Share on other sites

This is useful, but I can see possible improvements:

  • No need to have two Universal Actions. If you have just one named (e.g.) “Compress to Zip”, both zip and compress will work to filter for it.
  • Despite using $@ in the code (which suggests multiple inputs), the workflow only works for single inputs.
  • The unpacked zip creates a full folder structure of the original file. I.e. if we use the workflow to compress a file on the Desktop, when uncompressing the zip it will create a folder called Users, with a child with the user’s name (which can reveal who created it), which a child named Desktop, with finally a child which is the file. That will be unexpected for most people.
  • Zips can take time to create, so a notification and/or a sound when it’s done would provide an important clue.

Link to comment
Share on other sites

Updated to version 0.5.

 

Changes:

  • Use one universal action called "Compress to Zip"
  • Notify on completion.
  • Handle multiple selection and create files.zip in this case.
  • Do not include full paths to the selected files/folders in the zip file.
  • Do not overwrite zip file if it already exists.
     
Link to comment
Share on other sites

  • No need to do stuff like query="$@" if you’re not using query. That variable is an example.
  • No need to specify multiple exit codes in trap, you can just use EXIT.
  • When using the shell, you have to make sure to quote variables and commands. In doubt, quote. The workflow currently does not work properly if a file path has a space in it. The problem is this line:

 

dir="$(realpath $(dirname $1))"

 

Which needs to be:

 

dir="$(realpath "$(dirname $1)")"

 

Note that because realpath is used, the workflow requires Ventura. it took Apple a long time to include the tool. That is not a problem and will be noted in the Gallery page, merely informational.

Link to comment
Share on other sites

Bit of a 🤦‍♂️ moment when I saw the quote issue and TIL about the EXIT pseudo-signal. Thanks!

 

Both fixed, along with removing the unnecessary query variable.

 

I suspect that realpath isn't really needed, but really everyone should be upgrading to Ventura anyway, so I've left it in.

 

Link to comment
Share on other sites

Posted (edited)

Thank you for the fast fixes. The workflow will be live later today at https://alfred.app/workflows/akrabat/compress/.

 

Another tip for the future: you don’t need to specify a path to mktemp. You can just use the command and it’ll create a temporary file, and in a place (determined by the OS) with a lower chance of collisions.

 

Edited by vitor
Link to comment
Share on other sites

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