Automation and Integration with Other Productivity Tools

Automator Actions

BetterZip adds two actions to Automator:

Using Automator you can easily create BetterZip droplets, small apps onto which you can drop files and folders to compress using a pre-configured preset. The same works for extraction, of course.

Services

In previous versions of BetterZip you had two services that were available through the Services menu in other apps, most importantly in Finder. BetterZip 4 allows you to add as many services as you wish to the Services menu. Go to BetterZip > Preferences > Presets, choose the preset for which you want to add a service, and click the tools button (with the little gear) below the presets list. Choose “Add this Preset to the Services Menu…” and a sheet will drop down in which you may edit the name for the service. Click OK.

To make it easy to remove services again the tools button menu also has a command “Reveal Services Folder in Finder”. Remove the service by moving it to the trash from this folder.

BetterZip 4 supports some of the most widely used third-party productivity utilities:

Alfred Workflows

If you haven’t installed it during the first start of BetterZip, you can install the Alfred workflows at any time by selecting BetterZip > Install Alfred Workflows from the menu. This will add two File Actions to Alfred. “Extract with BetterZip” for archives and “Compress with BetterZip” for other files and folders. Choose the BetterZip action and you will be presented with a list of presets. Choose one and BetterZip will compress or extract the items.

LaunchBar Actions

Another popular productivity tool is LaunchBar. The LaunchBar actions for BetterZip are installed more like services than like the Alfred workflows, because they are preconfigured for one specific preset. Go to BetterZip > Preferences > Presets, choose the preset for which you want to add a LaunchBar Action, and click the tools button (with the little gear) below the presets list. Choose “Add this Preset to LaunchBar 6…” and a sheet will drop down in which you may edit the name for the action. Click OK.

Dropzone Actions

The creation of Dropzone actions works just like that for LaunchBar. Go to BetterZip > Preferences > Presets, choose the preset for which you want to add a Dropzone Action, and click the tools button (with the little gear) below the presets list. Choose “Add this Preset to Dropzone 3…” and a sheet will drop down in which you may edit the name for the action. Click OK.

Integration with Hazel

Hazel is a powerful control center for many file automation tasks and it plays very well together with BetterZip 4. The interaction of the two works best through AppleScript. Hazel has a basic archiving function, but if you want other formats than zip or encryption, BetterZip is here to help.

Here is a simple Hazel action that watches my DropZip folder and automatically zips every item dropped into it with BetterZip:

Note the output folder inside the DropZip folder. This is where the zipped files will end up without Hazel acting on them. You could, of course, save your zipped files to any other folder outside the DropZip folder, even iCloud Drive or Dropbox. In that case you wouldn't have to exclude "output" from the name matching in Hazel's rule definition. Just use "Any file" instead of "Name is not output".

See, I exclude the output folder from the Hazel rule, so that the created zip files are not zipped again and again and again. The first action is an AppleScript and after that the original file is moved to the Trash. Click the "Edit script" button and copy/paste the script code below.


tell application "BetterZip"
	archive theFile with preset "DropZip"
end tell

theFile is the dropped file supplied by Hazel to its scripts and DropZip is a preset name which I configured in BetterZip. If you prefer, you can include all BetterZip options in the script instead of using a preset.

Here is the BetterZip preset whose name needs to match the one in the script above and the destination folder set to output:

Controlling BetterZip with AppleScript

The base for all automation of BetterZip is its AppleScript support. For the complete scripting definition, open Script Editor and choose File > Open Dictionary… from the menu. Then select BetterZip from the list and click Choose.

Controlling BetterZip with Python

You can also script BetterZip with Python (and other languages) through the use of the ScriptingBridge. Here’s a short example that compresses the filename array items. When doing a queuedArchive or queuedUnarchive, you get back an id that you can use in subsequent calls to progress which returns the progress in percent (0..100). The call to output returns the produced archives. Since BetterZip will quit two seconds after all script operations are done, don’t use a too long polling interval, at least not at the end.


import ScriptingBridge
import time

preset = 'Clean and Zip'

BetterZip = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_("com.macitbetter.betterzip")

pid = BetterZip.queuedArchive_withPreset_withOptions_(items, preset, {})
if pid > 0:
	a = BetterZip.progress_(pid)
	while a < 100 and BetterZip.isRunning():
		a = BetterZip.progress_(pid)
		# a is the percentage done; do something with it?
		time.sleep (1)
	archives = BetterZip.output_(pid)
else:
	# handle error