Automation and Integration with Other Productivity Tools

Automator Actions

BetterZip adds two actions to Automator:

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 you 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 simply 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 you 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 LaunchBr 6…” and a sheet will drop down in which you may edit the name for the service. Click OK.

Dropzone Actions

The creation of Dropzone actions works just like that for LaunchBar. Go to BetterZip > Preferences > Presets, choose the preset you 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 service. 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:

The script itself looks like this:


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.

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_showUi_(items, preset, {}, True)
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